C#C
C#9mo ago
yourFriend

Regex help.

For Learning purposes
I want to match C# in given string. But the below pattern doesn't work for C# while it works for any alphabet word.

string s = "Just a random string in C#.";

string pattern = @"(?i:\bC#\b)";
Match match = Regex.Match(s, pattern);
// Doesn't work
// I also tried:
// @"(?i:\bC\#\b)" escaping #
// @"(?i:\bC\u0023\b)" using unicode

// But same pattern works for any other alphabetical word
string pattern2 = @"(?i:\brandom\b)";
Match match2 = Regex.Match(s, pattern2);
Was this page helpful?