The Functional XML Querying Tool
Contents
Text Patterns
A text pattern is an extended regular expression over the
alphabet of Unicode characters and is used for matching text nodes.
A text pattern matches a text node if the text contains a string that
matches the regular expression. For instance, the text pattern [Aa]utomat(a|on)
matches each text node whose text contains one of the words automata
or automaton, possibly starting with a capital
letter.
Character Patterns
Character patterns are the basic components of a text pattern:
They are text patterns that match strings of length one, i.e., single
characters. The simplest form of a character pattern is a character
to be matched. In order to match a range of characters, the special
characters . and ~
or bracket notation for specifying a list of character intervals
can be used. Moreover, a special character can be escaped using a backslash
\.
For instance, the character pattern A matches
the string A. The character pattern [a-zA-Z0-9]
matches any character between a and z,
A and Z or 0
and 9, i.e., alphanumeric ASCII characters.
The character pattern \[ matches the single
character [, and so does [[].
|
|
|
CharPattern
|
::=
|
.
|
|
|
|
|
~
|
|
|
|
|
Character
|
|
|
|
|
[CharInterval+]
|
|
|
|
|
[^CharInterval+]
|
|
|
|
CharInterval
|
::=
|
Character
|
|
|
|
|
Character-Character
|
|
|
|
Character
|
::=
|
UniChar
|
|
|
|
|
\UniChar
|
|
|
|
UniChar
|
::=
|
(a Unicode character)
|
|
A character pattern of the form [...] matches
all characters that are in one of the listed character intervals. If
the character pattern has the form [^...],
then it matches all characters that are not in any of the character
intervals. For instance, the character pattern [^0-9]
matches all characters except for digits.
Note that since character ^ has a special
meaning if ii follows the opening bracket, this character should never
be the first character interval. Similarly, character -
is interpreted in a special way if between two characters. In order
two be interpreted as an ordinary character, it must immediately follow
the [ or [^. You
can also use the backslash to escape the character: [\^]
matches the string ^.
Regular Expressions
Text patterns are made up from character patterns using regular expression
operators. Additionally, the two special symbols ^
and $ and the space character are allowed
and interpreted in a special way. The syntax is summarized by the following
grammar:
|
|
|
TextPattern
|
::=
|
|
|
|
|
|
^
|
|
|
|
|
$
|
|
|
|
|
CharPattern
|
|
|
|
|
TextPattern?
|
|
|
|
|
TextPattern*
|
|
|
|
|
TextPattern+
|
|
|
|
|
TextPattern TextPattern
|
|
|
|
|
TextPattern|TextPattern
|
|
|
|
|
(TextPattern)
|
|
The meaning of a text pattern is as follows:
|
The empty text pattern ( ) matches
the empty string. A character pattern matches all strings consisting
of a single character that matches the character pattern.
|
|
The concatenation of two text patterns is the text pattern that
matches all strings which result from concatenating two strings
that match the individual text patterns. For instance, the text
pattern foo, which is the concatenation
of the three character patterns f, o
and o, matches the string foo,
and the text pattern [tT]ree matches
the strings tree and Tree.
|
|
A text pattern composed with the |
operator indicates an alternative of two text patterns. It matches
any string matched by either of the two individual text patterns.
For instance, the text pattern automat(a|on)
matches the strings automata and automaton.
|
|
The ? operator specifies an optional
string: tp? is equivalent to
(tp|). For instance,
the tree pattern trees? matches the
strings tree and trees;
and the tree pattern white( |-)?space
matches the string whitespace as well
as white space
and white-space (We might also write
white[ -]?space
for this).
|
|
The operators * and +
specify a repetition of a subpattern: while +
requires at least one occurrence, *
allows also for omission of the part. For instance, the text pattern
[a-z]* matches a possibly empty sequence
of lower case ASCII letters, whereas [0-9]+
requires that at least one digit must be present.
Note that a text pattern of the form tp*
is equivalent to (tp+)?.
Note also that the individual instances of a repeated subpattern
need not match identical strings. Thus the text pattern (foo|bar)*
matches foobarfoofoo as well as barbarfoo.
|
|
Parentheses are used for grouping subpatterns. They need only
be employed if the operator precedences do not match the structure
of the pattern. The precedence of operators is such that ?,
* and + bind
most strongly, followed by concatenation and finally |.
For instance the text pattern a?b*|c+
is equivalent to ((a?)(b*))|(c+).
|
|
The two text patterns ^
and $ match the empty string. However,
^ only matches at the beginning of a
piece of text, i.e., before the first character, and $
only matches at the end of a text segment, i.e., after the last
character. Note that it doesn't make much sense to use ^
and $ other than at the beginning or
end of a text pattern.
^ and $
can be used for forcing a piece of text to match a text pattern
exactly rather than containing a match. For instance, the attribute
qualifier [@id~"^query$"] requires that
the value of attribute id be exactly
query, whereas [@id~"query"]
is fulfilled for all attribute values that contain the word query.
|
|
The space character is treated as an abbreviation of the text
pattern ~+, which matches a non-empty
sequence of white-space characters. The reason is that when searching
for a phrase, white space is usually not relevant, and the matching
should be independent of the line breaks or indentation. Therefore,
the text pattern to be or not to be
finds all occurrences of that phrase even if they are broken into
two lines. If the intention is to match exactly a single space
character, then it must be escaped with a backslash \
in the text pattern.
|