Boost logo

Boost Users :

From: John Maddock (john_at_[hidden])
Date: 2005-04-05 09:52:25


> I've looked at replacing the pcre library with boost regex,mainly
> because the C++ interface seems more usable than the plain C functions
> from pcre.
>
> The trouble is, I'm wasn't able to adjust regular expressions to the
> format boost regex uses. For instance, while pcre and others seem to
> like the expression "\?", boost throws bad_expression. The same goes
> for "\(", "\+" and others I'm using.
>
> So, I suppose the question is, is there a flag that can be set for the
> regex constructor that enables compatibility with a certain regex
> specification or should the regexp I gave as an example not be
> accepted ? Any hints would be kindly appreciated.

It should be completely compatible with pcre - I've even pinched many of
pcre's test cases (with permission) - but I suspect you're passing a string
literal and forgetting that the compiler will swallow up the first escape,
so if you pass "\?" the compiler will change this actually embed the string
"?" into the program, and that will cause the engine to throw a
bad_expression exception. Use "\\?" if you want to pass a literal backslash
to the regex engine. Of course this is a C/C++ issue, not a Boost.Regex
one, you'll have the same issue if you pass string literals to pcre.

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