Boost C++ Libraries

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

Click here to view the latest version of this page.
PrevUpHomeNext

Function template skip

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

Synopsis

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

Description

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];

Parameters:

skip

A regex that specifies which characters to skip.

Notes:

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".


PrevUpHomeNext