[Top] [All Lists]

Re: [xsl] XSLT Regex for Matching Curly Braces

2019-06-10 15:18:23

That will be Ok as you do not have nested instances, {aaa{bbb}ccc}
it would match from the first { to the first } so {aaa{bbb}  which is
probably not intended. It is not possible in general (for arbitrary
depth) to match nested brackets with a regular expression (that's
essentially what is implied by "regular")


On Mon, 10 Jun 2019 at 19:20, Don Smith dsmith_lockesmith(_at_)yahoo(_dot_)com
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

Thank you all,

I used Gerrit's suggestion <xsl:analyze-string select="." 
regex="\{{([^}}]+)\}}"> and it appears to work exactly as desired. Further 
testing TBA.

Thanks again,


On ‎Monday‎, ‎June‎ ‎10‎, ‎2019‎ ‎12‎:‎32‎:‎41‎ ‎PM‎ ‎CDT, 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

Agree, if expand-text is available (if one uses XSLT 3.0, for which there is 
almost no reason not to).

Sent from MailDroid

-----Original Message-----
From: "Michael Kay mike(_at_)saxonica(_dot_)com" 
To: xsl-list <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Mon, 10 Jun 2019 18:21
Subject: Re: [xsl] XSLT Regex for Matching Curly Braces

On 10 Jun 2019, at 17:56, Imsieke, Gerrit, le-tex 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

If you want to use xsl:analyze-string with XSLT 2.0 (or 3.0), you can put the 
regex in a variable, like so:

 <xsl:variable name="regex" as="xs:string" select="'\{([^}]+)\}'"/>

I think it's even clearer to use

<xsl:variable name="regex" as="xs:string" 

This way you avoid complications with single and double quotes as well as 
curly braces: the only characters that now have an XML or XSLT-defined 
special meaning are "&" and "<", and these fortunately don't have special 
meanings in regular expressions.

Michael Kay

XSL-List info and archive
EasyUnsubscribe (by email)
XSL-List info and archive
EasyUnsubscribe (by email)
XSL-List info and archive
EasyUnsubscribe (by email)
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com

<Prev in Thread] Current Thread [Next in Thread>