Opened 12 years ago

Closed 12 years ago

#4309 closed Bugs (fixed)

Negative lookbehind assertion error

Reported by: anonymous Owned by: John Maddock
Milestone: Boost 1.43.0 Component: regex
Version: Boost 1.43.0 Severity: Problem
Keywords: Cc:

Description

As soon as you include an OR-expression inside a negative lookbehind assertion, you get wrong results. Not sure if this is a bug, but I've tested this with multiple engines and I get different results.


Regex: (?<!foo|bar) \(

String: test bar (

NO MATCH (expected)


Regex: (?<!food|bar) \(

String: test bar (

MATCH (NOT expected)


Regex: (?<!fo|bar) \(

String: test bar (

MATCH (NOT expected)


This really makes it hard to match certain strings :(

Change History (4)

comment:1 by Steven Watanabe, 12 years ago

According to http://perldoc.perl.org/perlre.html#Extended-Patterns, the latter two are not allowed. (I believe that the default behavior of Boost.Regex is to match perl)

comment:2 by anonymous, 12 years ago

I wouldn't be too sure.

(?<!pattern) A zero-width negative look-behind assertion. For example /(?<!bar)foo/ matches any occurrence of "foo" that does not follow "bar". Works only for fixed-width look-behind.

Both foo and bar are fixed-width, so ORing them should also be fixed width. There is no quantifier used in the sample.

For comparison, in .NET, System.Text.RegularExpressions.Regex does it 'right'. The .NET regular expression engine is designed to be mostly compatible with Perl 5 regular expressions. Hmmm?

comment:3 by anonymous, 12 years ago

Expressions 2 and 3 should have been rejected - they're not supported either by Perl or by Boost.Regex. Will fix shortly, John.

comment:4 by John Maddock, 12 years ago

Resolution: fixed
Status: newclosed

(In [62563]) Some lookbehind assertions were accepted when they should not have been. Fixes #4309.

Note: See TracTickets for help on using tickets.