PHP Regex to match word in a sentence with optionally only other certain words -


i'm looking php regex match word in sentence optionally permit other words in sentence match should fail if there other words in sentence not in allowed list. eg:

the quick fox 

here i'm looking fox. 'the' , 'quick' ok if appear. since words optional

fox  

would ok too. however,

the quick brown fox 

is not ok. don't want brown fox.

feel free suggest way of doing needs blazing fast.

edit: words come before fox can appear in order

 quick fox 

should match too.

just make first 2 words optional.

^(?:(?:the )?(?:quick )?fox|(?:quick )(?:the )?fox|(?:fox )?(the )?quick|(?:the )?(?:fox )?quick)$ 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -