I am trying to get "a=.*" from the argument list in a URL (http:/a.b.com/?a=123) in Javascript.
/(.*[&|?])(a=.+?)(&.*)/.exec ("http:/a.b.com/?a=123&b=123")
gives me the expected and desired :
["http:/a.b.com/?a=123&b=123", "http:/a.b.com/?", "a=123", "&b=123"]
However, there might not be a following "&arg=val" and I need to be able to search for an optional trailing "&.*" (so adding '?' after the '&' on the third group. Hence :
/(.*[&|?])(a=.+?)(&?.*)/.exec ("http:/a.b.com/?a=123&b=123")
which gives me the unexpected :
["http:/a.b.com/?a=123&b=123", "http:/a.b.com/?", "a=1", "23&b=123"]
The second group now has only 1 character after the '=' and the remainder two '23' are part of the third group..
What I might be doing wrong ? Also any advice to do this a different/better way is also welcomed.
Thanks very much in advance !