开发者

Regex to match words

I'm looking for a Regex (using .NET) to match the word ass. The Reg开发者_如何学运维ex shouldn't match words like assignment.

How can I do this?


You are looking for word boundaries (\b):

\bass\b

This will match ass but not bass or assignment.


How about \bass\b ? This uses word boundaries to limit it to the single word.


Visit this page for full manual Word Boundaries


Most modern regular expression engines support the \b anchor, meaning a zero-width word boundary.

See this page for some examples using that (and other) anchor characters.


Will this work for you?

\bass\b


\b(ass)\b or \bass\b should be good.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜