[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: XSLT Regex for Matching Curly Braces
Hi David, Thanks for pointing that out. Fortunately I've no requirement for nested brackets. Gratitude. . .small things, eh? Don On bMondayb, bJuneb b10b, b2019b b03b:b18b:b22b bPMb bCDT, David Carlisle d.p.carlisle@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > \{{([^}}]+)\}} 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}B 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") David On Mon, 10 Jun 2019 at 19:20, Don Smith dsmith_lockesmith@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> 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, > > Don > > On bMondayb, bJuneb b10b, b2019b b12b:b32b:b41b bPMb bCDT, gerrit.imsieke@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> 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@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> > To: xsl-list <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> > Sent: Mon, 10 Jun 2019 18:21 > Subject: Re: XSLT Regex for Matching Curly Braces > > > > On 10 Jun 2019, at 17:56, Imsieke, Gerrit, le-tex gerrit.imsieke@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> 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: > > >B <xsl:variable name="regex" as="xs:string" select="'\{([^}]+)\}'"/> > > > I think it's even clearer to use > > <xsl:variable name="regex" as="xs:string" expand-text="no">{([^}]+)\}</xsl:variable> > > > > 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 > Saxonica > > XSL-List info and archive > EasyUnsubscribe (by email) > XSL-List info and archive > EasyUnsubscribe (by email) > XSL-List info and archive > EasyUnsubscribe (by email)
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|