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
  • 6,067
  • 5
  • 34
  • 51
Buda Gavril
  • 21,409
  • 40
  • 127
  • 196

0 Answers0