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
7.08Mb 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

Deviation by Scott M. Williams
From Russia with Lunch by David Smiedt
Natasha's Dance by Orlando Figes
Falling for Sarah by Cate Beauman
The Deep Zone: A Novel by James M. Tabor
A Young Man Without Magic by Lawrence Watt-Evans