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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -