/url?q=http://it.wikipedia.org/wiki/Spider-Man_(film)&sa=U&ei=iavVUKuFGsrNswbz74GQBA&ved=0CBYQFjAA&usg=AFQjCNEth5YspFPWp6CInyAfknlEvVgIfA
I need to get just
http://it.wikipedia.org/wiki/Spider-Man_(film)
I tried with \?q=(.*)&
but it consider last occurrence of &
, so I get
http://it.wikipedia.org/wiki/Spider-Man_(film)&sa=U&ei=iavVUKuFGsrNswbz74GQBA&ved=0CBYQFjAA
http://rubular.com/r/yBiGIMQTUV
You need to use reluctant matching to match till the first &
. With greedy matching (i.e. using *
instead of *?
), your pattern will match as long string as possible so as to satisfy the complete pattern.
So use this: -
\?q=(.*?)&
Or you can also use character class with negated &
which matches every character except &
: -
\?q=([^&]*)
Note that, if you don't want your (.*?)
to match empty string, then you should use +
quantifier. It matches 1 or more
occurrence.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With