...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::xpressive::mark_tag — Sub-match placeholder type, used to create named captures in static regexes.
// In header: <boost/xpressive/regex_primitives.hpp> struct mark_tag { // construct/copy/destruct mark_tag(int); // private static functions static unspecified make_tag(int); };
mark_tag
is the type of the global sub-match placeholders s0
, s1
, etc.. You can use the mark_tag
type to create your own sub-match placeholders with more meaningful names. This is roughly equivalent to the "named capture" feature of dynamic regular expressions.
To create a named sub-match placeholder, initialize it with a unique integer. The integer must only be unique within the regex in which the placeholder is used. Then you can use it within static regexes to created sub-matches by assigning a sub-expression to it, or to refer back to already created sub-matches.
mark_tag number(1); // "number" is now equivalent to "s1" // Match a number, followed by a space and the same number again sregex rx = (number = +_d) >> ' ' >> number;
After a successful regex_match()
or regex_search()
, the sub-match placeholder can be used to index into the match_results<>
object to retrieve the corresponding sub-match.