I spent a bit of time looking for the answer, but I couldn't find it, so, here's the question:
I'm getting this error:
StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw
exceptionjava.lang.IllegalStateException: No match found
at java.util.regex.Matcher.group(Matcher.java:536)
at extra.regex.checkRegex(regex.java:21)
And here's the code
public class regex {
public static String checkRegex(String check, String regex)
{
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(check);
m.matches();
return m.group(1);
}
}
I'm calling checkRegex() with this:
String query = request.getQueryString();//this query looks like "sel=45"
String regulex = "#^(.+)#"; //even this guy returns no matches
//out.println(query); //it is is not null
String result = regex.checkRegex(query, regulex);
out.println(result);
I've seen a few questions here, but all were about missing m.matches() or m.find(), but I've triple checked that.
matchesreturn?matches()returns a boolean, an extra check needed? @Reimeus, I've checked that via regex101, unfortunately, it matches completelymatches, it doesfind.