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

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

The replacement string supplied in the
replace
argument can contain the variables
$1
,
$2
, ...
to refer to parts of the input string that were matched by parts of the regular expression. If you want to include a
$
sign in the replacement string, you must write it as
\$
, and if you want to include a
\
character, you must write it as
\\
. (These rules might seem bizarre. But it was done this way for compatibility with other languages, and to allow other features to be added in the future.)

The variable
$N
refers to the substring of the input that was matched by the Nth parenthesized subexpression of the regex. You can find out which the Nth subexpression is by simply counting
(
characters from the first character of the regex. For example, in the regex
([0-9]+)([A-Z]+) ([0-9]+)
,
$1
refers to the digits at the start of the string,
$2
to the group of letters in the middle, and
$3
to the digits at the end. So if you want to insert a hyphen between the groups of letters and digits, you can write:

Other books

To Tame His Mate by Serena Pettus
Summer Of Fear by Duncan, Lois
Finding the Worm by Mark Goldblatt
Death's Sweet Song by Clifton Adams
Kathy's World by Shay Kassa
The Care of Time by Eric Ambler
Fearless by Tawny Weber