Representing Any Character

The period (.) has special significance in regular expressions; it matches any character except the line feed character (#xA). The period character represents only one matching character, but a quantifier (such as *) can be applied to it to represent multiple characters. Table 18-6 shows some examples of the wildcard escape character in use.

Table 18-6. The wildcard escape character

Regular expression

Strings that match

Strings that do not match

[a]

f.o

fao, fbo, f2o

fo, fbbo

f..o

faao, fbco, f12o

fo, fao

f.*o

fo, fao, fbcde23o

f [a]

f\.o

f.o

fao

[a] Assume a line feed character between f and o. This string does not match unless you are in dot-all mode.

It is important to note that the period loses its wildcard power when placed in a character class expression (within square brackets).

Some XQuery functions (namely matches, replace, and tokenize) allow you to indicate that the processor should operate in dot-all mode. This is specified using the letter s in the $flags argument. In dot-all mode, the period matches any character whatsoever, including the line feed character (#xA). See "Using Flags," later in this chapter, for more information.

Get XQuery 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.