Derin
Derin

Reputation: 2185

Regex to match words

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

Answers (6)

locoboy
locoboy

Reputation: 38960

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

Upvotes: 0

paxdiablo
paxdiablo

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

UserControl
UserControl

Reputation: 15179

Will this work for you?

\bass\b

Upvotes: 0

Saleh
Saleh

Reputation: 3032

Visit this page for full manual Word Boundaries

Upvotes: 1

Marc Gravell
Marc Gravell

Reputation: 1064184

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

Upvotes: 1

Daniel Hilgarth
Daniel Hilgarth

Reputation: 174457

You are looking for word boundaries (\b):

\bass\b

This will match ass but not bass or assignment.

Upvotes: 5

Related Questions