Consider these two urls:
http:website.com/?q=hello
http:website.com/?q=hello&z=world
I would like to match the part after the query url parameter q=
and (possibly) before another &
. That is, I would like to match hello
in the first string, and hello
in the second.
I am using the regex \?q=(.+?)&
but this of course fails to match the first hello
that is not preceded by &
.
Trying to make the &
optional with \?q=(.+?)&?
does not work either.
I do not understand what is the issue. Any ideas?
Thanks!