xsl-list
[Top] [All Lists]

Re: [xsl] one for the regex gods

2013-07-08 18:35:49


On 09.07.2013 01:05, Ihe Onwuka wrote:
I have this regex

<!-- remove commas embedded in amounts-->
<!-- also replace multiple hyphens with asterisks -->
<xsl:variable name="line"
select="replace(replace(.,'-{2,}','**********'),'(,(\d{3})+(\D|$))','$2')"/>

Have you considered using '$2$3' as the outer replacement?

But I’m wondering whether the regex is really intended as it is written here. If you are trying to replace repeating groups of (,(\d{3})) with each $2, it should be more like (,(\d{3}))+ instead of (,(\d{3})+…)

You can’t, however, refer to repeated occurrences of a captured substring. $2 will give you only the last, iirc.

If there were lookaheads in XPath 2, it might be feasible for repeated ,\d{3} groups.

Maybe you should just tokenize or xsl:analyze-string your lines on a tab, determine whether a given token represents a number and if it does, strip all commas. Then reassemble the line if needed.

Gerrit

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>