Subject: Re: [xsl] XSLT Regex for Matching Curly Braces From: "Liam R. E. Quin liam@xxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Tue, 11 Jun 2019 17:26:01 -0000 |
On Mon, 2019-06-10 at 18:21 +0000, Don Smith dsmith_lockesmith@xxxxxxxxx wrote: > Thank you all, > I used Gerrit's suggestion <xsl:analyze-string select="." > regex="\{{([^}}]+)\}}"> and it appears to work exactly as desired. As an addendum, i'll add that i tend to use [{] and [}] and the same for [(] and [)] so as not to have to worry about regular expression engines in which those are or aren't special -- in some, \( \) are for capturing and \{ \} are for counting, for example. So i end up with [{](^{}]+)[}] This is marginally less efficient than \{ and \} but that seldom matters in practice. I used [^{}] partly to avoid nested braces and partly because then the automatic brace matching in my editor will show the close one matching with the open one, and thatbs a feature that tends to reduce errors. Sometimes i use variables for bra and ket in XSLT, e.g. if ibm making CSS or JavaScript or something. But that's a separate issue from embedding them in XSLT and dealing with { } being for attribute value templates :) and Mike Kaybs solution is (unsurprisingly) the best for that. For a really complex expression, use the x flag: <xsl:variable as="xs:string" name="within-braces"> [{] <!--* opening bace *--> ( <!--* $1 *--> [^{}]+ <!--* not containing a brace *--> ) <!--* end $1 *--> [}] <!--* closing brace *--> </xsl:variable> and then fn:replace($input, $within-braces, 'x'), or more likely, <xsl:analyze-string regex="$within-braces" flags="x" . .. . > Liam -- Liam Quin, https://www.delightfulcomputing.com/ Available for XML/Document/Information Architecture/XSLT/ XSL/XQuery/Web/Text Processing/A11Y training, work & consulting. Barefoot Web-slave for http://www.fromoldbooks.org/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] XSLT Regex for Matching C, Don Smith dsmith_loc | Thread | Re: [xsl] XSLT Regex for Matching C, Imsieke, Gerrit, le- |
Re: [xsl] XSLT Regex for Matching C, Don Smith dsmith_loc | Date | Re: [xsl] XSLT Regex for Matching C, Imsieke, Gerrit, le- |
Month |