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: "Liam R. E. Quin liam@xxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 10 Mar 2025 23:25:33 -0000
On Mon, 2025-03-10 at 22:08 +0000, Martin Honnen martin.honnen@xxxxxx
wrote:
>
> On 10/03/2025 23:04, Martin Honnen martin.honnen@xxxxxxx wrote:
>
>
> B B  analyze-string("The person put 12 dollars into the jar",
> "[0-9]+")//*:match
>
> returns an element node
>
> B B  <match xmlns="http://www.w3.org/2005/xpath-functions";>12</match>

Or you can use
    replace($input, '^.*(\d+).*$', '$1')
which returns "12" as a string.

If there are newlines in the input, add the 's' flag so that . will
cross line boundaries:
    replace($input, '^.*(\d+).*$', '$1', 'm')

Both techniques are useful although i find the gratuitous namespace of
analyze-string() a slight pain :-)


--
Liam Quin,B https://www.delightfulcomputing.com/
Available for XML/Document/Information Architecture/XSLT/
XSL/XQuery/Web/Text Processing/A11Y training, work & consulting.
Barefoot Web-slave, antique illustrations: B http://www.fromoldbooks.org

Current Thread