javaxpathsaxonxpath-2.0

Escaping regex in XPath using SaxonJ HE


I am trying to make the below negative lookahead work in a matches() argument, of a XPath expression, using SaxonJ HE 12 (java):

//test[matches(me, '(?!0115)[0-9]{4}')]

I know I need to escape some chars like \() (and possibly ?) as those are relevant to Java too but all my attempts failed. The regexp, which tells to match 4 digits except 0115, works fine by itself but it doesn't once embedded in a XPath expression.

Here is the playground that can be used: xpath test That webpage specifically uses the Saxon HE java engine, I don't want (can't) use another one.

I know the workaround here, which is just to add another condition in the selector ... and me!='0115' but I want it to work as I have other complex regexps.

Is this a limitation of XPath? or a bug in Saxon?


Solution

  • Use //test[matches(me, '(?!0115)[0-9]{4}', ';j')], negative lookahead is only supported by the Java regular expression syntax, not by the standard XPath one.