Forum Moderators: coopster

Message Too Old, No Replies

Regular expression help

Match example.php?[anything except cat=]

         

CernyM

4:58 pm on May 18, 2008 (gmt 0)

10+ Year Member



I need to create a regular expression that will match:

example.php?anyparameter=whatever

except when

example.php?cat=whatever

is the parameter.

g1smd

7:35 pm on May 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You'll be testing the {QUERY_STRING} and looking for anything that is NOT "cat=whatever".

Also, test only for "example.php" so the rule only runs when that is the requested page.

eelixduppy

8:11 pm on May 18, 2008 (gmt 0)



It would probably look something like this:

if(isset($_SERVER['QUERY_STRING']) && !preg_match("/^cat=.+$/",$_SERVER['QUERY_STRING']))
#do something

CernyM

8:13 pm on May 18, 2008 (gmt 0)

10+ Year Member



It's not a web/PHP question per se. I don't have access to the query string information as a variable in this case.

eelixduppy

8:25 pm on May 18, 2008 (gmt 0)



What are you using this for? If not php is it apache's mod_rewrite? Something else? regex patterns match strings so you must have the query or uri string somewhere.

chorny

8:30 pm on May 18, 2008 (gmt 0)

10+ Year Member



Something like /example\.php\?(?!cat)[\w_-]+=.*/

CernyM

8:58 pm on May 18, 2008 (gmt 0)

10+ Year Member




What are you using this for? If not php is it apache's mod_rewrite? Something else? regex patterns match strings so you must have the query or uri string somewhere.

It's for Google Analytics goal tracking.