Bug 3866 - Incorrect regex matching when popping a group
Summary: Incorrect regex matching when popping a group
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: 2.10.x
Hardware: PC Linux
: Normal normal
Target Milestone: Untriaged
Assignee: Paolo Molaro
Depends on:
Reported: 2012-03-12 18:22 UTC by Jirka Hanika
Modified: 2014-11-23 22:55 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Jirka Hanika 2012-03-12 18:22:08 UTC
The following program demonstrates the bug.  The regex is supposed to match some a's, then an equal number of b's, then one more b.  However, the last "lookahead" b lets one extra a to the left of the correct match to be incorrectly matched as well.

This was reported on stack overflow for 2.8 but seems to be still in 2.10.

using System;
using System.Text.RegularExpressions;
public class Test {
public static void Main() {
 Console.WriteLine(new Regex(@"(?<A>a)+(?<-A>b)+(?(A)(?!))b").Match("aaaaaabbb"));
 // writes aaabbb instead of correct aabbb
Comment 1 Miguel de Icaza [MSFT] 2012-03-13 10:17:04 UTC

This is for your queue of Regex issues.
Comment 2 Miguel de Icaza [MSFT] 2014-11-23 22:55:21 UTC