[xsl] escape quotation marks in regular expression

Subject: [xsl] escape quotation marks in regular expression
From: "Wolfhart Totschnig wolfhart.totschnig@xxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 10 Jul 2022 05:51:48 -0000
Dear list,

I am receiving strings that may or may not be wrapped in double quotation marks. I would like to remove the quotation marks at the start and end of the string, if there are. There may also be quotation marks in the middle of the string, which should not be removed. I thought to use the replace() function for this, like so:

B B B select="replace(., '^\&quot;?(.+)\&quot;?$', '$1')"

But Saxon throws the following error:

B B B FORX0002: Syntax error at char 3 in regular expression: Escape character '"' not allowed

So what do I have to put instead of "\&quot;"? That is, what is the correct way to escape the quotation marks in the regular expression?

(I am aware that I could do this without a regular expression, i.e., with substring() and string-length(), but I would like to know how to do it with replace() since that seems simpler.)

Thanks in advance for your help!

Wolfhart

Current Thread