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

Between the Lives by Shirvington, Jessica
The Fertile Vampire by Ranney, Karen
Wild Blood (Book 7) by Anne Logston
Ghosts of Bungo Suido by Deutermann, P. T.
The War Widows by Leah Fleming
The Victor Project by Bradford L. Blaine
The Stranger From The Sea by Winston Graham
ONE NIGHT by ARUN GUPTA