Regex not being greedy enough

Posted by Chad on Stack Overflow See other posts from Stack Overflow or by Chad
Published on 2010-06-15T14:09:30Z Indexed on 2010/06/15 14:12 UTC
Read the original article Hit count: 181

Filed under:
|

I've got the following regex that was working perfectly until a new situation arose

^.*[?&]U(?:RL)?=(?<URL>.*)$

Basically, it's used against URLs, to grab EVERYTHING after the U=, or URL= and return it in the URL match

So, for the following

http://localhost?a=b&u=http://otherhost?foo=bar

URL = http://otherhost?foo=bar

Unfortunately an odd case came up

http://localhost?a=b&u=http://otherhost?foo=bar&url=http://someotherhost

Ideally, I want URL to be "http://otherhost?foo=bar&url=http://someotherhost", instead, it is just "http://someotherhost"

© Stack Overflow or respective owner

Related posts about regex

Related posts about language-agnostic