[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Analyze-string Regex to Match Content within Curly

Subject: Re: Analyze-string Regex to Match Content within Curly Braces
From: "Don Smith dsmith_lockesmith@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 17 Nov 2020 16:18:26 -0000
Re:  Analyze-string Regex to Match Content within Curly
 Thank you Martin for the solution.
Thank you Dr. Kay for the summary reminder:
To cope with the specialness in AVTs, double them,
To cope with the specialness in regexes, backslash-escape them.
So regex = "\{{[a-z]+\}}"
Don
    On Tuesday, November 17, 2020, 07:43:44 AM CST, Michael Kay mike@xxxxxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:  
 
 Curly braces are special in AVTs and they are special in regexes.
To cope with the specialness in AVTs, double them,
To cope with the specialness in regexes, backslash-escape them.
So regex = "\{{[a-z]+\}}"
should do the trick; or as Martin suggests, remove the AVT problem by using a variable (making sure you have expand-text="no")
Michael KaySaxonica


On 17 Nov 2020, at 12:43, Don Smith dsmith_lockesmith@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
Once again I find myself at a loss when trying to write a regex in analyze-string that matches on an open/close curly brace combination. I'm using XSLT 2.0 and Saxon PE-9.6.0.7.
Here's an example of the text content:
<text>In the be{opthyphen}gin{opthyphen}ning</text>

I need to match all occurrences (none nested) of an open and close curly brace with the text that occurs in-between.
I started with this successful regex in a non-XSLT context:
{[a-z]+}

Then because the analyze-string @regex is an AVT I double the curly braces:
{{[a-z]+}}

thus:
<xsl:analyze-string select="$content" regex="{{[a-z]+}}" >

That produces the compile error "Syntax error at char 0 in regular expression. No expression before quantifier". I've tried everything I can think of in terms of using escapes, etc. I've also tried defining the regex as a variable and then referencing it from @regex. But I'm just missing something in the regex itself (I think). All help is appreciated.
DonXSL-List info and archiveEasyUnsubscribe(by email)

XSL-List info and archiveEasyUnsubscribe(by email)  

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.