I am trying to use regex to match a query string pattern and am having some issues. The URL is "http:www.domain.com/dir/page.aspx". This page can have a variety of query string vaiables and values attached in a non-specific order. What i want to do is get the value of one of these variables and use it. Thus, for all of these examples:
http:\\www.domain.com/dir/page.aspx?city=name
http:\\www.domain.com/dir/page.aspx?area=codes&city=name
http:\\www.domain.com/dir/page.aspx?area=codes&city=name&state=ofmind
http:\\www.domain.com/dir/page.aspx?city=name&state=ofmind
http:\\www.domain.com/dir/page.aspx?area=codes&state=ofmind&city=name
http:\\www.domain.com/dir/page.aspx?area=codes&city=name&state=ofmind&dat=dis&foo=bar
I want to extract the value "name" from the city variable and use it. What I've come up thus far is:
/dir\/page.aspx\?(.*&)?city=(.*)(?=&.*)/
and using $2 for that value.
This works ok for some cases but doesnt seem to catch them all. I believe my issue is here:
city=(.*)
and that I need to stop capturing at the first appearance of an ampersand, but my random copy and paste efforts have not been successful. Can anyone explain how I would catch any and all characters until a particular one appears?