Alex Rivera | Logout

Matching all words except one

Asked 2010-01-21T09:05:14.683
42

Say I have a sentence:

I am a good buy and bad boy too

How to select every word except boy in this sentence using regular expression ?

Edit
Report

1 Answer

69

You can use negative look behind:

\w+\b(?<!\bboy)

Or negative look ahead since not all support negative look behind

(?!boy\b)\b\w+

You can read about negative look ahead here

answered 2010-01-21T09:10:24.320

Your Answer