Bug 3810 - Incorrect regex matching with RegexOptions.RightToLeft and Regex.Match(String, Int32, Int32) overload
Summary: Incorrect regex matching with RegexOptions.RightToLeft and Regex.Match(String...
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: 2.10.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2012-03-08 09:01 UTC by Korbinian Abenthum
Modified: 2014-08-12 11:38 UTC (History)
4 users (show)

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

Test case showing the incorrect behavior. (609 bytes, text/plain)
2012-03-08 09:01 UTC, Korbinian Abenthum

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 Korbinian Abenthum 2012-03-08 09:01:53 UTC
Created attachment 1485 [details]
Test case showing the incorrect behavior.

The Regex.Match(String input, Int32 beginning, Int32 length) overload behaves
differently than the Microsoft implementation.

  new Regex(@".*", RegexOptions.RightToLeft).Match("ABCDEFGHI", 2, 6)
matches "AB" in Mono and "CDEFGH" in Microsoft .NET 4.0

According to MS documentation of the overload, their behavior is correct.

This bug seems to be based on a misunderstanding.

There is an overload Regex.Match(String input, Int32 startat) where it is
correct for the Regex engine to start at the given position and scan from
there to the left if RegexOptions.RightToLeft is set. Note that the position
here is explicitly called "startat".

It appears that the same logic is used for the
Regex.Match(String input, Int32 beginning, Int32 length) overload. However,
the parameters here are intended to only define the /substring/ that is to be
scanned, not where to start the scan. As I understand it this overload should
behave exactly like Regex.Match(input.Substring(beginning, length)).
Comment 1 Korbinian Abenthum 2012-03-08 09:03:54 UTC
Test case output:

Microsoft .NET 4.0:
| Match: 'User XXXX'
| Match: 'Us'
| Match: 'er XXX'
| Match: 'er XXX'

| Match: 'User XXXX'
| Match: 'Us'
| Match: 'Us'
| Match: 'er XXX'