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 - Regular expression - in the range:.*
string
:string
- Match string - in the range:.*
Example:
code
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:
code
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.