It's not that hard to build a backtracking matching engine, at least if performance is not important. I did that in the past for the C# syntax tree used in a decompiler.
Basically the syntax tree has a bunch of additional (non-syntax) pattern nodes, that support flexible regex-style matching of a pattern-tree against a concrete syntax tree.
Example pattern: https://github.com/icsharpcode/ILSpy/blob/1100d64e4bbd878164...
Implementation: https://github.com/icsharpcode/ILSpy/tree/1100d64e4bbd878164...