开发者

Simple regex word question

开发者 https://www.devze.com 2023-04-07 02:20 出处:网络
I have the regex: TheComment = Regex.Replace(TheComment, \"(\\\\@\" + r + \"\\b)\", \"<span style=\\\"background:yellow;font-weight:bold;\\\">@\" + ThisUser.Username + \"</span>\", RegexO

I have the regex:

TheComment = Regex.Replace(TheComment, "(\\@" + r + "\b)", "<span style=\"background:yellow;font-weight:bold;\">@" + ThisUser.Username + "</span>", RegexOptions.IgnoreCase);

This is an example pattern

(\\@to\b)

I want this to match @To but not @Tom. At the moment it's not matching, if I strip the \b away it works but it matches @Tom as well w开发者_开发知识库hich is musn't.


You have to escape \ and not @. Plus, you got to move \b out of the selection.

@"(@" + r + @")\b"
0

精彩评论

暂无评论...
验证码 换一张
取 消