System Debug Reference Manual (32650-90888)

532 AppendixA
Patterns and Regular Expressions
Character Classes (Match Any One of the Following Characters)
The "." and other reserved characters are called metacharacters. The special meaning of
any metacharacter can be turned off by preceding it with the escape character "\". Thus,
"\." matches the literal period character and "\\" matches the literal backslash.
Two positional metacharacters exist. "^" matches the beginning of a line: "^HP" is a
regular expression that matches "HP" only if it occurs as the first two characters of the
line. Similarly, "$" matches the end of a line: "HP$" matches "HP" only if it is the last thing
on a line. Of course, these can work together: "^HP$" matches a line that contains only
"HP".
Character Classes (Match Any One of the Following
Characters)
The metacharacter "[" signals that the characters following, up to the next "]", form a
character class, that is, a regular expression that matches any single character from the
bracketed list. The character class "[aA]" matches "a" or "A". A dash "-" is used to signify a
range of characters in the ASCII collating sequence. For example, "[a-zA-Z]" matches any
alphabetic character, while "[0-9]" matches any numeric character. If the first character in
a character class is an "^", then any character not in the class constitutes a match; for
example, [^a] matches any character except an "a".
Expression Closure (Match Zero or More of the Previous
Expressions)
Any regular expression that matches a single character (that is, everything but "^" and
"$") can be followed by the character "*" to make a regular expression that matches zero or
more successive occurrences of the single character pattern. The resulting expression is
called a closure. For example, "x*" matches zero or more x's; "xx*" matches one or more
"x's"; "[a-z]*" matches any string of zero or more lowercase letters. If there is a choice of the
number of characters to be matched, the longest possible string is used even when a match
with the null string is equally valid. "[a-zA-Z]*" matches an entire word (which may be a
null string); "[a-zA-Z][a-zA-Z]*" matches at least an entire word (one or more letters but
not a null string); and ".*" matches a whole line (which may be a null string). Any
ambiguity in deciding which part of a line matches an expression is resolved by choosing
the match beginning with the leftmost character, then choosing the longest possible match
at the point. So "[a-zA-Z][a-zA-Z0-9_]*" matches the leftmost Pascal identifier on a line,
"(.*)" matches anything between parentheses (not necessarily balanced), and "..*" matches
an entire line of one or more characters but not a null string.