(data =~ /regex/)
(data =~ /regex/i)
(data !~ /regex/)
(data !~ /regex/i)
Regular Expression Comparisons
The regular expression operators perform regular expression matching
on the data. The data
field can be an attribute reference or data,
as with the other comparison operators. The /regex/
field must be a valid regular expression.
The =~
operator evaluates to true
when data
matches the
/regex/
expression. Otherwise, it evaluates to false
.
The !~
operator evaluates to true
when data
does not match the
/regex/
expression. Otherwise, it evaluates to true
.
The regular expression comparison is performed on the string
representation of the left side of the comparison. That is, if the
left side is an integer, the regular
expression will behave is if the value 0
was the literal string
"0"
. Similarly, if the left side is an
&Attribute-Name, then the regular expression will
behave is if the attribute was printed to a string, and the match was
performed on the resulting string.
The syntax of the regular expression is defined by the regular expression library used by the local system. These are usually Posix regular expressions.
The regular expression may be followed by a single i
character. The
i
indicates that the regular expression match should be done in a
case-insensitive fashion.
When the =~
operator is used, then parentheses in the regular
expression will define variables that contain the matching text.
The special variable %{0}
contains a copy of the result of
evaluating the data field. The variables %{1}
through %{16}
will
contain the substring matches, starting from the left-most parentheses.
If there are more than eight parentheses, the additional results will be
discarded and will not be placed into any variables.
Examples:
if (User-Name =~ /@example\.com$$/) { …