Boost logo

Boost Users :

From: John Maddock (john_at_[hidden])
Date: 2005-08-02 04:27:27

>I am using regex_match() from Boost 1.32.0. I am well famililar with
>Perl's regular expression, but I got a surprise from Boost's regex_match().
>My basic code is
> static const regex CHAR(" char ");
> regex_match(newSpec, CHAR)
> If newSpec is " char ", then it matches, of course. However, if newSpec
> is " char * ", it doesn't match. Hmmmm.
> In my Perl experience, a regex of " char " says match those six characters
> if found ANYWHERE in newSpec. This would mean that a Boost regex of "
> char " would match a newSpec of " char * ", but it doesn't seem to.
> If I change the regex to ".* char .*", then it matches, implying that
> Boost's regex of " char " is being treated as if it were Perl's "^ char
> $".
> I could add the ".*" before and after each of my (many) regular
> exressions. However, I'm guessing there is a match_flag_type value which
> would do this for me. Unfortunately, none of the match constant
> descriptions seem to be what I need.
> How should I write a Boost regex so that it would find " char " anywhere
> in the input string regardless of any prefix or suffix?

At the start of the documentation for regex_match there is a sentense in
bold which reads:

Note that the result is true only if the expression matches the whole of the
input sequence. If you want to search for an expression somewhere within
the sequence then use regex_search. If you want to match a prefix of the
character string then use regex_search with the flag match_continuous set.

So you need regex_search.


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at