Why should I use double curly braces in my RegEx?

I perform a little regular expression in one of my xsl transforms ( xsl:analyze-string) and stumbled upon this effect, which made me rather uncomfortable because I really did not find any explanation ...

I searched for Non-Breaking-Spaces and En-Spaces, so I used the construct \p{Z}. According to many examples in the XSLT 2.0 Programmers Guide by Michael Kay, this should work. RegExBuddy also claims :)

Now my SaxonHE9.4N tells me

Error in regex: net.sf.saxon.trans.XPathException: expected ({)

After several tests and errors, I simply doubled the brackets \p{{Z}}... and it worked !? But this time, RegExBuddy does not approve!

Can someone give me an explanation of this effect? I could not find anything pleasant on the Internet ...

Thanks in advance!

Edit: I tried the same thing inside a function replace(), and the version with two brackets did not work. I had to do this with separate brackets!

+4
source share
1 answer

In an attribute value template, curly braces are special syntax specifying the XPath expression to be evaluated. If you need literal curly braces, you need to avoid doubling them :

. XPath , ({}). , , {{ }}.

:

     

   StringLiteral XP .

AVT, regex :

:

regex , . , , regex = ". {{1,5}}". , , , regex = "{'[0-9] {1,5} [a-z] {3} [0-9] {1,2}'}" .

( .)

+6

Source: https://habr.com/ru/post/1524496/


All Articles