Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.

Function template skip

boost::xpressive::skip — Specify which characters to skip when matching a regex.


// In header: <boost/xpressive/regex_primitives.hpp>

template<typename Skip> unspecified skip(Skip const & skip);


skip() instructs the regex engine to skip certain characters when matching a regex. It is most useful for writing regexes that ignore whitespace. For instance, the following specifies a regex that skips whitespace and punctuation:

 // A sentence is one or more words separated by whitespace
 // and punctuation.
 sregex word = +alpha;
 sregex sentence = skip(set[_s | punct])( +word );

The way it works in the above example is to insert keep(*set[_s | punct]) before each primitive within the regex. A "primitive" includes terminals like strings, character sets and nested regexes. A final *set[_s | punct] is added to the end of the regex. The regex sentence specified above is equivalent to the following:

 sregex sentence = +( keep(*set[_s | punct]) >> word )
                        >> *set[_s | punct];



A regex that specifies which characters to skip.


Skipping does not affect how nested regexes are handled because they are treated atomically. String literals are also treated atomically; that is, no skipping is done within a string literal. So skip(_s)("this that") is not the same as skip(_s)("this" >> as_xpr("that")). The first will only match when there is only one space between "this" and "that". The second will skip any and all whitespace between "this" and "that".