Maybe I am doing something wrong here but it seems weird to me that when I try to match the string "radiologic examination eye detect foreign body" against the regular expression "\b*ct\b" on regexr.com then I find no match but when I try and do the same thing using a C# program, it matches. C# code is given below. Am I doing/checking something wrong?
string desc = "radiologic examination eye detect foreign body";
string regex = "\\b" + "*ct" + "\\b";
if (Regex.IsMatch(desc, regex))
{
String x = Regex.Replace(desc, regex, " " + "ct" + " ").Trim();
Console.WriteLine(x);
}
Thanks in advance!
It's matching because you've got an asterisk in there.
An asterisk means:
Matches the preceding character zero or more times
So it's not matching the \b
at all, but still satisfying the above condition.
Remove this and it no longer matches:
string regex = "\\b" + "ct" + "\\b";
As for why it doesn't match on Regexr, I don't know, but for me it does actually match on reFiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With