\b - , , .
Letters, numbers, and underscores are word characters. *, SPACE, and parens are characters other than words. therefore, when you use \b*abc\bas your template, it does not match your input, because * is not a word. Similarly for your parens-related model.
To solve this problem, you will need to eliminate it \bin cases where your input (unscreened) pattern begins or ends with characters without a word.
public void Run()
{
String input = "[ abc() *abc ]";
Match(input, @"\babc\b", 2);
Match(input, @"\babc\(\)", 1);
Match(input, @"\*abc\b", 1);
Match(input, @"\*abc\b ", 1);
}
private void Match(String input, String pattern, int expected)
{
MatchCollection mc = Regex.Matches(input, pattern, RegexOptions.IgnoreCase);
Console.WriteLine((mc.Count == expected)? "PASS ({0}=={1})" : "FAIL ({0}!={1})",
mc.Count, expected);
}
source
share