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.57Mb 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

Duet for Three by Joan Barfoot
Words Unspoken by Elizabeth Musser
Getting Wilde by Jenn Stark
The Billionaire by Jordan Silver
The Demon Abraxas by Calish, Rachel
The Perfect Match by Kristan Higgins
Shadows (Black Raven Book 1) by Barcelona, Stella