B-19
User Guide for Cisco Security MARS Local Controller
78-17020-01
Appendix B Regular Expression Reference
Conditional Subpatterns
(?<=\d{3}...)(?<!999)foo
This time the first assertion looks at the preceding six characters, checking that the first three are digits,
and then the second assertion checks that the preceding three characters are not "999".
Assertions can be nested in any combination. For example,
(?<=(?<!foo)bar)baz
matches an occurrence of "baz" that is preceded by "bar" which in turn is not preceded by "foo", while
(?<=\d{3}(?!999)...)foo
is another pattern that matches "foo" preceded by three digits and any three characters that are not "999".
Conditional Subpatterns
It is possible to cause the matching process to obey a subpattern conditionally or to choose between two
alternative subpatterns, depending on the result of an assertion, or whether a previous capturing
subpattern matched or not. The two possible forms of conditional subpattern are
(?(condition)yes-pattern)
(?(condition)yes-pattern|no-pattern)
If the condition is satisfied, the yes-pattern is used; otherwise the no-pattern (if present) is used. If there
are more than two alternatives in the subpattern, a compile-time error occurs.
There are three kinds of condition. If the text between the parentheses consists of a sequence of digits,
the condition is satisfied if the capturing subpattern of that number has previously matched. The number
must be greater than zero. Consider the following pattern, which contains non-significant white space to
make it more readable (assume the PCRE_EXTENDED option) and to divide it into three parts for ease
of discussion:
( \( )? [^()]+ (?(1) \) )
The first part matches an optional opening parenthesis, and if that character is present, sets it as the first
captured substring. The second part matches one or more characters that are not parentheses. The third
part is a conditional subpattern that tests whether the first set of parentheses matched or not. If they did,
that is, if subject started with an opening parenthesis, the condition is true, and so the yes-pattern is
executed and a closing parenthesis is required. Otherwise, since no-pattern is not present, the subpattern
matches nothing. In other words, this pattern matches a sequence of non-parentheses, optionally
enclosed in parentheses.
If the condition is the string (R), it is satisfied if a recursive call to the pattern or subpattern has been
made. At "top level", the condition is false. This is a PCRE extension. Recursive patterns are described
in the next section.
If the condition is not a sequence of digits or (R), it must be an assertion. This may be a positive or
negative lookahead or lookbehind assertion. Consider this pattern, again containing non-significant
white space, and with the two alternatives on the second line:
(?(?=[^a-z]*[a-z])
\d{2}-[a-z]{3}-\d{2} | \d{2}-\d{2}-\d{2} )
Содержание CS-MARS-20-K9 - Security MARS 20
Страница 20: ...Contents xx User Guide for Cisco Security MARS Local Controller 78 17020 01 ...
Страница 356: ...17 16 User Guide for Cisco Security MARS Local Controller 78 17020 01 Chapter 17 Network Summary Summary Page ...
Страница 420: ...20 28 User Guide for Cisco Security MARS Local Controller 78 17020 01 Chapter 20 Queries and Reports Reports ...
Страница 580: ...Glossary GL 4 User Guide for Cisco Security MARS Local Controller 78 17020 01 ...