Re: [xsl] Is there a way in XSLT/XPath to find the portion of a string that matches a pattern?

Subject: Re: [xsl] Is there a way in XSLT/XPath to find the portion of a string that matches a pattern?
From: "Roger L Costello costello@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 11 Mar 2025 22:12:04 -0000
Liam gave this wicked cool way to return the portion of a string that matches
a regex pattern:

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 jar'"/>
<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?

/Roger

Current Thread