Opened 8 years ago

Closed 8 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:


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 :(

Attachments (0)

Change History (4)

comment:1 Changed 8 years ago by Steven Watanabe

According to, the latter two are not allowed. (I believe that the default behavior of Boost.Regex is to match perl)

comment:2 Changed 8 years ago by anonymous

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 Changed 8 years ago by anonymous

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 Changed 8 years ago by John Maddock

Resolution: fixed
Status: newclosed

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

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain John Maddock.
The resolution will be deleted.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.