My String:
Code:
Pattern pattern = Pattern.compile("(browse/)(.*)(\">)");
Matcher matcher = pattern.matcher(match);
return matcher.group(1);
Getting error:
java.lang.IllegalStateException: No match found
Tested my regex here, it does match:
http://regexpal.com/?flags=g®ex=(browse%2F)(.*)(%5C%22%3E)&input=%3Ca%20href%3D%22https%3A%2F%2FMYURL%2Fbrowse%2FTEST-53%22%3EFOO.BAR%3C%2Fa%3E%3C%2Fp%3E
解决方案
You first need to do
matcher.find()
to trigger the actual search. Usually like this:
Pattern pattern = Pattern.compile("(browse/)(.*)(\">)");
Matcher matcher = pattern.matcher(match);
if (matcher.find())
return matcher.group(1);
You should probably be using a different regex, though:
Pattern pattern = Pattern.compile("browse/([^<>\"]*)\">");
will be safer and more efficient (and provide the correct value in group number 1).