Skip to main content

RCS1186: Use Regex instance instead of static method

Properties​

PropertyValue
Default SeverityHidden
Minimum language version-

Examples​

Example #1​

diagnostic.cs
private void Bar()
{
bool isMatch = Regex.IsMatch("abc", @"\w");
}
fix.cs
private readonly Regex _regex = new Regex(@"\w");

private void Bar()
{
bool isMatch = _regex.IsMatch("abc");
}

Applies to​