I have the following code to parse by Regex:
const string patern = @"^(\p{L}+)_";
var rgx = new Regex(patern);
var str1 = "library_log_12312_12.log";
var m = rgx.Matches(str1);
It returns only one match and it is “library_”. I have read a lot of resources and it should not contain underscore, should it?
Your pattern includes the
_, so the match does too. If you only want the group, you need to specify that. It’ll be in group 1 (as group 0 is always the whole match):