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

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

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

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'd use preg_match_all() :)
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

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

Post by CoderGoblin »

Arghh why is it the simplest solutions are the ones I miss out on... Once again thanks Feyd.
Post Reply