Following regex giving me java.lang.IllegalStateException: No match found
error
String requestpattern = "^[A-Za-z]+ \\/+(\\w+)";
Pattern p = Pattern.compile(requestpattern);
Matcher matcher = p.matcher(requeststring);
return matcher.group(1);
where request string is
POST //upload/sendData.htm HTTP/1.1
Any help would be appreciated.
No match has been attempted. Call find()
before calling group()
.
public static void main(String[] args) {
String requeststring = "POST //upload/sendData.htm HTTP/1.1";
String requestpattern = "^[A-Za-z]+ \\/+(\\w+)";
Pattern p = Pattern.compile(requestpattern);
Matcher matcher = p.matcher(requeststring);
System.out.println(matcher.find());
System.out.println(matcher.group(1));
}
Output:
true
upload
The Matcher#group(int) throws :
IllegalStateException - If no match has yet been attempted, or if the
previous match operation failed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With