Modify

Ticket #4309 (closed Bugs: fixed)

Opened 4 years ago

Last modified 4 years ago

Negative lookbehind assertion error

Reported by: anonymous Owned by: johnmaddock
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 :(

Attachments

Change History

comment:1 Changed 4 years ago by steven_watanabe

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 Changed 4 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 4 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 4 years ago by johnmaddock

  • Status changed from new to closed
  • Resolution set to fixed

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

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


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

 
Note: See TracTickets for help on using tickets.