In Java I have:
String params = "depCity=PAR&roomType=D&depCity=NYC";
I want to get values of depCity parameters (PAR,NYC).
So I created regex:
String regex = "depCity=([^&]+)";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(params);
m.find() is returning false. m.groups() is returning IllegalArgumentException.
What am I doing wrong?
It doesn’t have to be regex. Since I think there’s no standard method to handle this thing, I’m using something that I copied from somewhere (and perhaps modified a bit):
So, when you call it, you will get all parameters and their values. The method handles multi-valued params, hence the
List<String>rather thanString, and in your case you’ll need to get the first list element.