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
11.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

Waking Up With a Rake by Mia Marlowe, Connie Mason
The Undesired Princess by L. Sprague deCamp
The Soul's Mark: HUNTED by Ashley Stoyanoff
Diamond Eyes by A.A. Bell
A Rare Chance by Carla Neggers
Fashion Academy by Sheryl Berk
Mine to Take by Alexa Kaye
Haunted Harbours by Steve Vernon