diff --git a/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.Match.Tests.cs b/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.Match.Tests.cs index c168ed04c54396..af65e57e203a4d 100644 --- a/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.Match.Tests.cs +++ b/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.Match.Tests.cs @@ -385,6 +385,11 @@ public static IEnumerable Match_MemberData() yield return (@"(\(.*?\))+?;", "(a)b);", RegexOptions.None, 0, 6, true, "(a)b);"); yield return (@"(\(.*?\))*;", "(a)b);", RegexOptions.None, 0, 6, true, "(a)b);"); yield return (@"(\(.*?\))*?;", "(a)b);", RegexOptions.None, 0, 6, true, "(a)b);"); + // Lazy quantifier inside optional group where the lazy loop must expand for the rest of the pattern to match. + yield return (@"a(b.*?c)?d", "abccd", RegexOptions.None, 0, 5, true, "abccd"); + yield return (@"a(b.*?c)?d", "abcd", RegexOptions.None, 0, 4, true, "abcd"); + yield return (@"a(b.*?c)?d", "ad", RegexOptions.None, 0, 2, true, "ad"); + yield return (@"a(b.*?c)?d", "abce", RegexOptions.None, 0, 4, false, string.Empty); // Non-backtracking body: optimization correctly applies. These verify bodies without backtracking // inside the outer loop are still correctly matched after the outer loop is made atomic. yield return (@"\w+(\(abc\))?,", "Foo(abc),", RegexOptions.None, 0, 9, true, "Foo(abc),");