Reputation: 91
I'm trying to remove a query string parameter from a url using regular expressions (in .NET if it matters) without luck.
The solutions I've found on Stackoverflow use the HttpValueCollection, or similar helpers, or doesn't use the whole url including the ? before the query string. I would like this to work in plain regex if possible.
Parameter to remove: remove=me
.
Sample urls:
http://{domain}/?remove=me
http://{domain}/?remove=me&foo=bar
http://{domain}/?baz=qux&remove=me&foo=bar
http://{domain}/?baz=qux&remove=me
http://{domain}/?baz=qux&tmpremove=me
After the parameter is removed the remaining url should be intact. No "&&", "?&", or "http://{domain}/&..." and it shouldn't touch the "tmpremove=me" :-)
Cheers
Upvotes: 0
Views: 1312
Reputation: 4614
Match: (?:[?&]remove=me$)|(?:([?&])remove=me&(.+))
Replace with: $1$2
Upvotes: 1