java - Extract a substring by using regex doesn't work -


i have string this:

string source = "https://1116.netrk.net/conv1?prid=478&orderid=[6aa3482b-519b-4127-abee-debcd6e39e96]" 

i want extract orderid inside [ ]. wrote 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 exception

java.lang.indexoutofboundsexception: no group 1 

any idea what's wrong? thanks

you need escape brackets:

pattern p = pattern.compile("\\[(.*?)\\]"); 

Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -