© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•11mo ago•
10 replies
yourFriend

Regex help.

For Learning purposes
I want to match
C#
C#
in given string. But the below pattern doesn't work for
C#
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);
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);
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ REGEX help!
C#CC# / help
3y ago
❔ Regex help
C#CC# / help
3y ago
✅ Regex help pls:
C#CC# / help
3y ago
✅ help with regex
C#CC# / help
4y ago