Regex expression to mach one of many strings in php -


i totally new regex , want match if value 1 of following

cs,ch,es,ee,it,me

till have tried

if (preg_match("/^[cs|ch|es|ee|it|me]{2}$/",$val))     echo "true"; else     echo "false"; 

its working fine true cases returns true reverse of them sc,hc etc. helpful if refer source/books learn php.

remove character class [] regex , wrap them using (). remove {2} not necessary anymore.

if (preg_match("/^(cs|ch|es|ee|it|me)$/",$val)) 

and you.


Comments

Popular posts from this blog

c# - SelectList with Dictionary, add values to the Dictionary after it's assigned to SelectList -

how can i manage url using .htaccess in php? -

ios - I get the error Property '...' not found on object of type '...' -