XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition (609 page)

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
9.94Mb size Format: txt, pdf, ePub

is
b#
. If you want to match the shortest possible substring, add a
?
after the quantifier to make it non-greedy:
replace(“banana”, “(an)+?a”, “#”)
is
b#na
. Note that the final three characters of
banana
don't result in a replacement, because two matches never overlap: the middle
a
cannot participate in two different matching substrings.

Another situation that can cause two different substrings to match at the same position is where the regex contains two alternatives that both match. For example, the regex
a|ana
could match the second character of
banana
, or it could match characters 2 to 4. The rule here is that the first (leftmost) alternative wins. So the result of
replace(“banana”, “a|ana”, “#”)
is
b#n#n#
, whereas the result of
replace(“banana”, “ana|a”, “#”)
is
b#n#
.

Other books

Cleopatra by Joyce Tyldesley
Rough and Tumble by Crystal Green
i f2cd308009a8236d by Guinevere
Suspicious (On the Run) by Rosett, Sara
Weremones by Buffi BeCraft-Woodall
New America 02 - Resistance by Richard Stephenson
Deadly Shores by Taylor Anderson
The Adultery Club by Tess Stimson
30 Days by Larsen, K