Opened 14 years ago

Closed 14 years ago

#2340 closed Bugs (wontfix)

Regex : Invalid preceding regular expression problem

Reported by: jcombe@… Owned by: John Maddock
Milestone: To Be Determined Component: regex
Version: Boost 1.36.0 Severity: Problem
Keywords: regex Cc:

Description

I have the following code:-

std::cout << "BUILD REGEX" << std::endl; try {

boost::u32regex uregex= boost::make_u32regex ( "(.*?)(
b?
s?)(
w*?)&(
w+?)(
b
s?&?)(.*)" , boost::regex::perl );

} catch ( boost::regex_error x ) {

std::cout << "REGEX ERROR << x.what() <<" << std::endl; return false;

} std::cout << "REGEX BUILT" << std::endl; return false;

When I compile this code and then run it, it throws an exception and prints this message:-

REGEX ERROR [Invalid preceding regular expression]

When I use this line instead

boost::u32regex uregex= boost::make_u32regex ( "(.*?)(
b
s?)(
w*?)&(
w+?)(
b
s?&?)(.*)" , boost::regex::perl );

It does work.

Both regular expressions compile and run as I expect in Perl. Is it a bug that this regex does not work in Boost?

Change History (1)

comment:1 by John Maddock, 14 years ago

Resolution: wontfix
Status: newclosed

In a strict sense this is a bug (in the sense that Perl accepts it and we don't), but the problematic part of the original regular expression is meaningless:

\b?

means "maybe match a word boundary, or maybe don't bother", so either way it consumes zero characters and will *always* succeed. The alternative form (which is also an error in Boost.Regex):

\b+

Is also rather meaningless and exactly equivalent to

\b

My gut feeling at present, is that these almost always represent errors in the regular expression, and are generally best diagnosed as such. But... please do reopen if you can think of a legitimate use case :-)

HTH, John.

Note: See TracTickets for help on using tickets.