Table of Contents
regcmp
Table of Contents
Prototype: regcmp(regex, string)
Return type: boolean
Description: Returns whether the anchored regular expression
regex
matches the string.
Arguments:
regex
: regular expression, in the range:.*
string
:string
, in the range:.*
Example:
body common control
{
bundlesequence => { subtest("mark") };
}
bundle agent subtest(user)
{
classes:
"invalid" not => regcmp("[a-z]{4}","$(user)");
reports:
!invalid::
"User name $(user) is valid at exactly 4 letters";
invalid::
"User name $(user) is invalid";
}
Output:
R: User name mark is valid at exactly 4 letters
If the string contains multiple lines, then it is necessary to code these
explicitly, as regular expressions do not normally match the end of line
as a regular character (they only match end of string). You can do this
using either standard regular expression syntax or using the additional
features of PCRE (where (?ms)
changes the way that ., ^
and $
behave), e.g.