-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Result of Regex.Match("wtfb",@"(.)()+?b") is not same as new Regex(@"(.)()+?b",RegexOptions.Compiled).Match("wtfb") #111051
Comments
Tagging subscribers to this area: @dotnet/area-system-text-regularexpressions |
Typo in the expected behavior. It is expected that the interpreted result matches compiled. |
Verified - the interpreted mode has a different result than both compiled and generated via I'll mark this as a bug and for v10 however with "help wanted". cc @stephentoub |
Do I need to submit new issues for other regular expression problems that appear to be bugs? Such as:
|
Hello! I'd like to create a PR for this. Can you please assign the issue to me? |
@ovidiucosteanet, if you'd like to give it a go, we'd welcome the help. Thanks. |
@stephentoub @ovidiucosteanet Maybe it is related to this issue using System;
using System.Text.RegularExpressions;
string pattern = @"(()+?){2}";
//pattern = @"(()+?)+";
//pattern = @"(()+?)*";
//pattern = @"(()+?){1,2}";
string input = "WTF123a1";
int timeOut = 10;
Regex regex = new Regex(pattern, RegexOptions.None, TimeSpan.FromMilliseconds(timeOut));
var mhes = regex.Matches(input);
try
{
//var matchCount = mhes.Count;// will throw TimeOutException if memory is enough
for (var i = 0; i < 1000; i++)
{
Console.WriteLine(mhes[i].Index + " , " + mhes[i].Length);
}
}catch(Exception e)
{
Console.WriteLine("Interpreted : "+e.Message);
} Output:
And I do not know why changing the quantifier to something like using System;
using System.Text.RegularExpressions;
string pattern = @"(()+?){2,100}";
string input = "WTF123a1";
int timeOut = 10;
Regex regex = new Regex(pattern, RegexOptions.None, TimeSpan.FromMilliseconds(timeOut));
var mhes = regex.Matches(input);
try
{
for (var i = 0; i < 1000; i++)
{
Console.WriteLine(mhes[i].Index + " , " + mhes[i].Length);
}
}catch(Exception e)
{
Console.WriteLine("Interpreted : "+e.Message);
} Output:
|
using System;
using System.Text.RegularExpressions;
string pattern = @"(()+?){2,100}";
string input = "1";
int timeOut = 10;
Regex regex = new Regex(pattern, RegexOptions.None, TimeSpan.FromMilliseconds(timeOut));
//var match = regex.Match(input);
try
{
var b = regex.IsMatch(input);
//Console.WriteLine(match.Index + " , " + match.Length);
}catch(Exception e)
{
Console.WriteLine("Interpreted : "+e.Message);
} Output:
|
Description
If pattern includes
()+?
, thenRegex.Match(input,pattern)
will match differnetnew Regex(pattern ,RegexOptions.Compiled).Match(input)
Some discussions in GitHub Discussion #110976
Reproduction Steps
Output:
Expected behavior
Output:
Actual behavior
Output:
It looks like
()+?
would make nearest outside brackets start at where the empty loop began, and this effect maybe gradually spread to group 0 or not.Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: