Web Hosting Talk







View Full Version : Combining Regular Expressions


hsbsitez
01-03-2009, 05:29 PM
I use 2 regular expressions to do the following:
User enters: genre:comedy type:direct hello
The script removes genre and type switch, so it becomes: hello
There isn't a specified order in which the switches have to occur. Also, a user can expand the genre switch to something like(separated by commas or semi-colons): genre:comedy;action;
I use following expressions:
$key = preg_replace('/genre:([a-zA-Z\,\;]*)/', '', $key);
$key = preg_replace('/type:([a-zA-Z\,\;]*)/', '', $key);How can I combine the two patterns into one?

Xenatino
01-03-2009, 06:33 PM
This will do the job:
$key = preg_replace('/(genre|type):([a-zA-Z\,\;]*)/', '', $key);

hsbsitez
01-03-2009, 06:56 PM
Thank you. :)