I’m writing a checker with Regex, and I’m testing results with one of the popular tools:
https://regex101.com/r/DeMWEy/1
I have a list of strings that should match:
Process(Bystronic.Ads.GraphQL)\% Processor Time
Process(Bystronic.ParameterTuning.WebApi.Service)\\% Processor Time
Process(Bystronic.Ads.GraphQL)\\IO Write Bytes/sec
Process(DcCutting)\\IO Read Bytes/sec
Process(DcCutting)\\% Processor Time
And a regex that should match all of them.
"Process(.+)\\.+"
Here is a MVC:
using System.Text.RegularExpressions;
public class MainClass
{
private static bool IsProcessMatch(string column)
{
return Regex.IsMatch(column, "Process(.+)\\.+");
}
public static void Main()
{
var result1 = IsProcessMatch("Process(Bystronic.Ads.GraphQL)\\% Processor Time");
var result2 = IsProcessMatch("Process(Bystronic.ParameterTuning.WebApi.Service)\\% Processor Time");
var result3 = IsProcessMatch("Process(Bystronic.Ads.GraphQL)\\IO Write Bytes/sec");
var result4 = IsProcessMatch("Process(DcCutting)\\IO Read Bytes/sec");
var result5 = IsProcessMatch("Process(DcCutting)\\% Processor Time");
Console.WriteLine(result1);
Console.WriteLine(result2);
Console.WriteLine(result3);
Console.WriteLine(result4);
Console.WriteLine(result5);
}
}
I’m getting a match in the first and second one, but not in the rest. Can somebody explain me the difference between them?
>Solution :
C# treats the pattern a little different than the regex engine used page that you posted. On the left side there is a menue where you can choose the flavor. If you choose C# you will see:
that one little detail is missing: @ in your code. The page will add it for you
private bool IsProcessColumn(string column)
{
return Regex.IsMatch(column, @"Process(.+)\\.+");
}
Here is a fiddle for testing
