More Atoms

Atoms that exactly match a character are the simplest atoms that can be used in a pattern facet. The other atoms that can be used in pattern facets are special characters, a wildcard that matches any character, or predefined and user-defined character classes.

Special Characters

Table 9-1 shows the list of atoms that match a single character, exactly like the characters you’ve already seen, but they also correspond to characters that must be escaped or (for the first three characters on the list) that are just provided for convenience.

Table 9-1. Special characters

Character

Description

\n

Newline (can also be written as 
 — because it’s an XML document).

\r

Carriage return (can also be written as 
).

\t

Tabulation (can also be written as 	)

\\

Character \

\|

Character |

\.

Character .

\-

Character -

\^

Character ^

\?

Character ?

\*

Character *

\+

Character +

\{

Character {

\}

Character }

\(

Character (

\)

Character )

\[

Character [

\]

Character ]

Wildcard

The dot character (.) has a special meaning; it’s a wildcard atom that matches any valid XML characters except newlines and carriage returns. As with any atom, a dot may be followed by an optional quantifier; .* (dot, asterisk) is a common construct to match zero or more occurrences of any character. To illustrate the usage of .* (and the fact that the pattern facet is a Swiss Army knife), a pattern facet can define the integers that are multiples of ...

Get RELAX NG 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.