Metacharacters

Within a regular expression, most characters represent themselves. For example, the regular expression A represents a capital A. There are, of course, special characters that are processed differently:

.

By default, this matches any character except the newline character. In dot-all mode, this matches the newline character as well.

^

By default, this represents the beginning of the string literal. In multiline mode, this represents the beginning of a line within the string.

[XPath] Use of the caret to indicate that the beginning of a string or line is an addition to the regular expression syntax defined by XML Schema.

The caret can also be used inside a character class expression to indicate the negation of that character set. For example, [a-f] represents the letters a through f, while [^a-f] represents every character except the letters a through f.

$

[XPath] By default, this represents the end of the string literal. In multiline mode, this represents the end of a line within the string.

\

Escapes the following character.

|

The union operator. The expression A|B matches both A and B. It does not match AB.

?

Zero or one of a pattern. For example, A[A-Z]?Z matches AZ and ABZ, but not ABCZ.

*

Zero or more of a pattern. For example, A[A-Z]* matches any string of uppercase basic Latin characters that starts with A and is followed by zero or more uppercase Latin characters. The strings A, ABC, AA, and AREALLYLONGSTRING all match this expression.

+

One or more of a pattern. For example, ...

Get XSLT, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.