user478280
user478280

Reputation:

PHP reg exp ignore word

Trying to get a reg exp in PHP to work, I need it to match only if it doesn't start with a certain word.

Ex. Our ignore word will be "dave"

bill.smith <--- match<br/>
dave.smith <--- ignore<br/>
clyde.hancock <--- match<br/>

My current code is a bit of a mess, I'm not sure how to properly ignore with word boundaries (I hope I was on the right path??)

Anyways, any help is appreciated.

Thanks

Upvotes: 0

Views: 869

Answers (1)

mario
mario

Reputation: 145512

You can use a (?!...) negative lookahead assertion for that:

preg_match('/^(?!dave\b)\w+\.\w+/', ...

Upvotes: 2

Related Questions