I have a String with a url like this: http://www.website.com/search?productId=1500
How do I get the value of productId with regular expression?
I have a String with a url like this: http://www.website.com/search?productId=1500
How do I get the value of productId with regular expression?
If you really want to do that:
However, there are libraries to parse URL query arguments and they will also do things like URL-decoding the arguments. Regexes can't do that.
Here's a question on SO that explains how to use libraries and even a code snippet for parsing query string arguments from URLs properly: Parse a URI String into Name-Value Collection
If you know that the desired number is prefixed by
productId=
, then why not work withsubstring
?I would probably use
URLEncodedUtils
from Appache Commons.outpit
1500
.But if you really want to use regex you can try