Regular expression to match multiple query string parameter / value pairs

About working on it, but thought that someone might have already dealt with it, so ...

I am looking for an elegant (and isapi rewrite compatible) regular expression to search for three known parameter / value pairs in querystring, regardless of order, and also retrieve all other parameters by deleting these three.

abc = 123 def = 456 and ghi = 789 are all known fixed lines. They may appear in any order in the query string and may or may not be the only parameters, or may or may not be adjacent. It must be smart and not correspond to aabc = 123 or abc = 123 4 (therefore, each parameter found must be enclosed in square brackets by the character &,?, # Or the end of the line). The output I want is a new query string with the remaining parameters.

I will probably hit the logic in the morning, so bonus points if you can solve this problem before I try to do it.

+1
source share
4 answers

, . , .

+1
s/(\?|\#|\&)(abc=123|def=456|ghi=789)(\&|\#|$)//g

, ( ) . , , , , , | .

0

:

RewriteRule ^/oldpage.htm\?(.\*)(?<=\?|&)(?:abc=123&|def=456&|ghi=789&)(.\*)(?<=&)(?:abc=123&|def=456&|ghi=789&)(.\*)(?<=&)(?:(?:abc=123|def=456|ghi=789)(?:&|#|$))(.\*) /newpage.htm?$1$2$3  [I,RP,L]

, , . lookAhead/lookbehind, (? <= (? =), -, , / , .

, URL- , ? URL- "/newpage.htm?". , RewriteCond, URL- 4+ , . :

RewriteCond URL ^/oldpage.htm\?([^#]\*=[^#]\*&){3,}[^#]\*=[^#]\*.\*

RewriteRule ^/oldpage.htm\?(.\*)(?<=\?|&)(?:abc=123&|def=456&|ghi=789&)(.\*)(?<=&)(?:abc=123&|def=456&|ghi=789&)(.\*)(?<=&)(?:(?:abc=123|def=456|ghi=789)(?:&|#|$))(.\*) /newpage.htm?$1$2$3  [I,RP,L]

RewriteRule ^/oldpage.htm\?(?:abc=123|def=456|ghi=789)&(?:abc=123|def=456|ghi=789)&(?:abc=123|def=456|ghi=789)(.\*) /newpage.htm$1 [I,RP,L]

($ 1 # url ​​... ?) , URL-/oldpage.htm?abc=123&abc=123&abc= 123 , , .

- - ?

0
source

There are decoders with requests. There are many related topics, especially on this site.

Some of them.

At first

Second

And javadocs link for apache decoder.

0
source

All Articles