![]() |
Home | Libraries | People | FAQ | More |
boost::xpressive::check — For adding user-defined assertions to your regular expressions.
// In header: <boost/xpressive/regex_actions.hpp> template<typename T> ( t);
A user-defined assertion is a kind of semantic action that evaluates a Boolean lambda and, if it evaluates to false, causes the match to fail at that location in the string. This will cause backtracking, so the match may ultimately succeed.
To use check()
to specify a user-defined assertion in a regex, use the following syntax:
sregex
The assertion is evaluated with a
object that delineates what part of the string matched the sub-expression to which the assertion was attached.sub_match
<>
check()
can be used with an ordinary predicate that takes a
object as follows: sub_match
<>
// A predicate that is true IFF a sub-match is // either 3 or 6 characters long. ssub_match
Alternately, check()
can be used to define inline custom assertions with the same syntax as is used to define semantic actions. The following code is equivalent to above:
// match words of 3 characters or 6 characters. sregex
Within a custom assertion, _
is a placeholder for the
That delineates the part of the string matched by the sub-expression to which the custom assertion was attached. sub_match
<>
Parameters: |
|