I\'m using Pattern
/Matcher
to get the response code in an HTTP response. groupCount
returns 1, but I get an exception when trying to g
pattern.matcher(input)
always creates a new matcher, so you'd need to call matches()
again.
Try:
Matcher m = responseCodePattern.matcher(firstHeader);
m.matches();
m.groupCount();
m.group(0); //must call matches() first
...
You are constantly overwriting the matches you got by using
System.out.println(responseCodePattern.matcher(firstHeader).matches());
System.out.println(responseCodePattern.matcher(firstHeader).groupCount());
Each line creates a new Matcher object.
You should go
Matcher matcher = responseCodePattern.matcher(firstHeader);
System.out.println(matcher.matches());
System.out.println(matcher.groupCount());