0

I'm trying to check if a log record starts with a log level and log date prefix. Here is an example of log record:

[7][20170731 10:36:39:754][18] [just a text] another test

Here is what I've tried:

//string text = "[7][20170731 10:36:39:754][18] [just a text] another test";
string text = "[7][20170731]";
var pattern = "[\\d{1}][\\d{8}\\s\\d{2}:\\d{2}:\\d{2}:\\d{3}].*";

if (Regex.IsMatch(text, pattern))
{
    Console.WriteLine("match");
}
else
{
    Console.WriteLine("not match");
}

But my problem is that with the second version of the text variable Regex.IsMatch returns true even if it's obvious that it's not a match.

So is my pattern wrong?

Mighty Badaboom
  • 5,854
  • 5
  • 29
  • 50
Buda Gavril
  • 20,719
  • 39
  • 122
  • 185

0 Answers0