I have a query string that can look like this:
?blah=1&phoneNum=123-456-7890
OR
?phoneNum=123-456-7890
I'm using this regex: phoneNum=[^&]+&? to remove the substring phoneNum=__ from the query string, but it leaves a trailing & in the first case, which is no me gusta.
How do I adapt my regex pattern to optionally remove the preceeding &? so it removes both:
phoneNum=123-456-7890
AND
&phoneNum=123-456-7890
from the query string?
&?phoneNum=[^&]+&?... Although i am not sure WHY you are splitting your own query string instead of using a query string parser. Are you writing your own parser? What programming language are you using?