I trying to use java pattern matching to extract the http response code from a single line in the http response header, but for some reason it is not matching. I dont suppose anyone could point out where i am going wrong..?
This is my code:`
private static String getSubString(String regex, String data ) {
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(data);
if(matcher.matches()) {
return matcher.group(1);
}
return null;
}`
And this is my test input to the method:
data = "HTTP/1.1 400 Bad Request";
regex = "([0-9][0-9][0-9])";
for some reason matcher.matches() is returning false.
Thanks heaps for any help anyone can provide Corey