Using xsl replace function with regular expression to find multiple instances
Posted: Wed Jul 12, 2023 2:04 pm
Hi,
I am trying to write an XSL template using replace() function to escape occurrences of $ sign within a string, specifically when $ sign exists within opening and closing double brackets e.g. for following input
Here is a $ sign [[Buy $1000 or more and get $100 credit from us]]
I want
Here is a $ sign [[Buy \$1000 or more and get \$100 credit from us]]
returned.
However I don't know how many $ signs will exist within double square brackets.
The following will replace the first occurrence of $ sign within double square brackets and I want to know if there is a way of adding a grouping and multiplier to cause it to work for any number of occurrences in the input string?
Any advice appreciated,
Regards,
Ann
I am trying to write an XSL template using replace() function to escape occurrences of $ sign within a string, specifically when $ sign exists within opening and closing double brackets e.g. for following input
Here is a $ sign [[Buy $1000 or more and get $100 credit from us]]
I want
Here is a $ sign [[Buy \$1000 or more and get \$100 credit from us]]
returned.
However I don't know how many $ signs will exist within double square brackets.
The following will replace the first occurrence of $ sign within double square brackets and I want to know if there is a way of adding a grouping and multiplier to cause it to work for any number of occurrences in the input string?
Code: Select all
<xsl:variable name="escapeDollar" select="replace($originalText, '(\[\[.*?)\$(.*?\]\])', '$1\\\$$2')"/>
Regards,
Ann