Skip to content

SYSLIB1045 Use GeneratedRegexAttribute replaces verbatim string with regular string #78113

@MaceWindu

Description

@MaceWindu

Description

It is quite common to use verbatim strings to declare regex as it could contain a lot of escape sequences and with regular strings it looks like back-slach circus.

Currently SYSLIB1045 refactoring replaces verbatim strings with regular strings.

Reproduction Steps

private static readonly Regex _regex = new(@"[`~!@#\$%\^&*\(\)_\+\-={}\|\[\]\\:"";'<>\?,\./№ ]+");

Expected behavior

[GeneratedRegex(@"[`~!@#\$%\^&*\(\)_\+\-={}\|\[\]\\:"";'<>\?,\./№ ]+")]
private static partial Regex MyRegex();

Actual behavior

[GeneratedRegex("[`~!@#\\$%\\^&*\\(\\)_\\+\\-={}\\|\\[\\]\\\\:\";'<>\\?,\\./№ ]+")]
private static partial Regex MyRegex();

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions