Boost logo

Boost Users :

From: John Maddock (john_at_[hidden])
Date: 2007-01-26 05:31:23


Lynn Allan wrote:
> ooops ... and thanks for the very prompt help to this regex newbie
> ... I'm very much at the "trial and error" state of getting regex
> statements to work.
>
> Would one of the following be the preferred "assignment"?
> reg.assign("(\\<and\\>|\\<can\\>|\\<did\\>|\\<the\\>|\\<in\\>|\\<a\\>)");
> or
> reg.assign("\\<(and|can|did|the|in|a)\\>");
>
> Both seem to work, but perhaps this regex newbie is missing a better
> alternative.

The latter looks more elegant to me. Make the opening parenthesis a (?: if
you don't actually want to capture a sub-expression.

> What is the "x modifier"? I looked up the perl explanation, and the
> boost::regex documentation, but that seemed related to formatting the
> statement itself.
>
> Also, thanks for the time and effort you put into boost::regex ...
> development and ongoing support.

It causes whitespace in the expression to be ignored. You can turn it on in
the flags passed to assign:

reg.assign("\\<(and|can|did|the|in|a)\\>",
boost::regex::perl|boost::regex::mod_x);

Or you can embed it in the expression:

"(?x)\\<(and | can | did | the | in | a)\\>" // whitespace ignored

HTH,

John.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net