Regex in URL Rewriting to match Querystring Parameter Values in any order? -
many url rewriting utilities allow regex matching. need urls matched against couple of main querystring parmeter values no matter order appear in. example let's consider url having 2 key parameters id= , lang= in no specific order, , maybe other non-key params interspersed.
an example url matched key params in order:
- http://www.example.com/surveycontroller.aspx?id=500&lang=4 or
- http://www.example.com/surveycontroller.aspx?lang=4&id=500
maybe interspersed non-key params:
- http://www.example.com/surveycontroller.aspx?lang=3&id=1&misc=3&misc=4 or
- http://www.example.com/surveycontroller.aspx?id=1&misc=4&lang=3 or
- http://www.example.com/surveycontroller.aspx?misc=4&lang=3&id=1 or
- etc
is there regex pattern match against querystring param value in order, or best duplicate rules, or in general should other means?
note: main querystring values captured using brackets i.e. id=(3)&lang=(500) , substituted destination url, that's not focus of question.
i suggest parsing query string dictionary , working there, if want regex, can use alternation+repetition match in order (without inlining possible sequences). python example:
>>> import re >>> p = re.compile(r'(?:[?&](?:abc=([^&]*)|xyz=([^&]*)|[^&]*))+$') >>> p.findall('x?abc=1&jjj=2&xyz=3') [('1', '3')] >>> p.findall('x?abc=1&xyz=3&jjj=2') [('1', '3')] >>> p.findall('x?xyz=3&abc=1&jjj=2') [('1', '3')]
Comments
Post a Comment