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 lettersathroughf, while[^a-f]represents every character except the lettersathroughf.$[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|Bmatches bothAandB. It does not matchAB.?Zero or one of a pattern. For example,
A[A-Z]?ZmatchesAZandABZ, but notABCZ.*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 stringsA,ABC,AA, andAREALLYLONGSTRINGall match this expression.+One or more of a pattern. For example, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access