matches
Condition (Regular Expressions)
The condition
expr
matches
pattern
or
expr
matches (
pattern)
interprets pattern as a pattern (a regular expression) and
tests whether expr matches pattern. Patterns are defined as
follows:
|
alternative}
*
| ?
| +
]}
?
), at least once (+
), or arbitrarily often,
including zero times (*
).
Normally, these operators are greedy, i.e. they try to match as
much as possible. If you put a ?
behind a postfix operator, it
will try to match as few characters as possible. This can make a
difference if you're assigning variables in your pattern.
(
pattern )
[
[^
] range {range} ]
^
is the first one in the class, the
expression represents exactly one character that is not contained
in one of the ranges.
.
-
character2]
*?+[]^-.\|()
*?+[]^-.|()
, it must be preceded by
a \\
(pattern escape). To insert the pattern escape itself, you
have to double it: \\\\
.
You can divide the pattern into segments:
$surf matches ("un|in|im|ir|il", ".*", "(en)?")
is is the same as
$surf matches ("(un|in|im|ir|il).*(en)?")
A section of the string can be stored in a variable by suffixing the respective
pattern with :
variable_name, as in
$surf matches ("un|in|im|ir|il": $a, ".*")
For backwards compatibility, you may also prefix the pattern with the variable name, as in
$surf matches $a: "un|in|im|ir|il", ".*"
The variables defined by pattern matching are only defined in the statement
sequence which is being executed if the pattern matching is successful.
A matches
condition may not have variable definitions in it if it
is
or
condition),
not
condition), or