I have a string like this:
String source = "https://1116.netrk.net/conv1?prid=478&orderid=[6aa3482b-519b-4127-abee-debcd6e39e96]"
I want to extract orderid which is inside [ ]. I wrote this method:
public String extractOrderId(String source)
{
Pattern p = Pattern.compile("[(.*?)]");
Matcher m = p.matcher(source);
if (m.find())
return m.group(1);
else
return "";
}
But I always get Exception
java.lang.IndexOutOfBoundsException: No group 1
Any idea what's wrong? Thanks
You need to escape brackets: