Reputation: 2185
I'm looking for a Regex (using .NET) to match the word ass. The Regex shouldn't match words like assignment.
How can I do this?
Upvotes: 2
Views: 1948
Reputation: 882656
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.
Upvotes: 1
Reputation: 1064184
How about \bass\b
? This uses word boundaries to limit it to the single word.
Upvotes: 1
Reputation: 174457
You are looking for word boundaries (\b
):
\bass\b
This will match ass
but not bass
or assignment
.
Upvotes: 5