Skip to content

Compiled regex patterns like "(?<=()*?)a" thow exception Bad label content in ILGenerator. #117601

@longxya

Description

@longxya

Description

When Compiled regex patterns contain lookbehind assertions, and lookbehind assertion contain a group construction or anchor which quantifier is lazy and minimum = 0, the .NET regex engine throws Bad label content in ILGenerator.

Reproduction Steps

using System;
using System.Text.RegularExpressions;

string input = "a";
string pattern="(?<=()??)a";
//pattern="(?<=()*?)a";
//pattern="(?<=(){0,100}?)a";
//pattern="(?<!()*?)a";
//pattern="(?<=(?:)*?)a";
//pattern="(?<=(wtf)*?)a";
//pattern="(?<=^*?)a";
//pattern=@"(?<=\A*?)a";
//pattern=@"(?<=(wtf)*?)b";

//pattern="(?<=(wtf)*?)";//this pattern would not throw Exception
try
{
	Match matchCompiled = new Regex(pattern, RegexOptions.Compiled).Match(input);
	Console.WriteLine(matchCompiled.Value);
}
catch(Exception ex)
{
	Console.WriteLine(ex.Message);
}

Expected behavior

Output:

a

Actual behavior

Output:

Bad label content in ILGenerator.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions