regex - PHP preg_match "AND" operator -


i use "or" operator "|" match onle of words of $name variable

$name = "one 5 6 two"; if (preg_match('/(one|two)/i', $name)) {return true;} 

what operator should use preg_match have "and" condition if words inside of $name?

i.e.

if (preg_match('/(two "and" five)/i', $name)) {return true;} 

if still want use regex, you'll need positive lookaheads:

if (preg_match('/^(?=.*one)(?=.*two)/i', $name)) {return true;} 

it's not recommended simple stuff (kind of overkill), , gets messy more complex stuff...


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -