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.
精彩评论