Page 1 of 1

preg_match. | is for OR, can you simply do an AND ?

Posted: Wed Aug 17, 2005 8:01 am
by CoderGoblin
I have a list of search parameters say alpha, beta and gamma and I need to compare them with a string.
the '.*(alpha|beta|gamma).*' pattern can check if one of these exists but I need to check if they all exist within the string in any order. Is there a simple way of doing this (back references or some such). I have tried to read up the syntax in the manual but must admit the explanations of the more complex features are double dutch to me 8O.

I know I could do each of the "options" in its own match or even a pattern like '.*(alpha.*beta.*gamma|.*beta.*alpha.*gamma|.*beta.*gamma.*alpha|.... all combinations' but there must be a better way.

Thanks for any assistance.

Posted: Wed Aug 17, 2005 8:12 am
by feyd
I'd use preg_match_all() :)

[Solved]preg_match. | is for OR, can you simply do an AND ?

Posted: Wed Aug 17, 2005 8:17 am
by CoderGoblin
Arghh why is it the simplest solutions are the ones I miss out on... Once again thanks Feyd.