Subject: Re: [xsl] Is there a way in XSLT/XPath to find the portion of a string that matches a pattern? From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Tue, 11 Mar 2025 22:25:49 -0000 |
Liam gave this wicked cool way to return the portion of a string thatmatches a regex pattern:
jar'"/>
replace($input, '^.*(\d+).*$', '$1')
However, I did some testing, and it's not returning the desired results:
<xsl:variable name="TEXT" select="'The person put 12 dollars into the
<xsl:variable name="INTEGER" select="'[0-9]+'"/>
<xsl:value-of select="replace($TEXT,'^.*(' || $INTEGER || ').*$', '$1')"/>
Result: 2 <-- should be 12
Another test:
<xsl:variable name="TEXT" select="'SATSET'"/>
<xsl:variable name="VOWELS" select="'A|E|I|O|U'"/>
<xsl:value-of select="replace($TEXT,'^.*(' || $VOWELS || ').*$', '$1')"/>
Result: E <-- should be A
What am I doing wrong?
I guess you need non-greedy matching for the .* with .*? e.g. replace($TEXT,'^.*?(' || $INTEGER || ').*$', '$1')
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Is there a way in XSLT/XP, Roger L Costello cos | Thread | Re: [xsl] Is there a way in XSLT/XP, Liam R. E. Quin liam |
Re: [xsl] Is there a way in XSLT/XP, Roger L Costello cos | Date | Re: [xsl] Is there a way in XSLT/XP, Liam R. E. Quin liam |
Month |