“No match Found” when using matcher's group method

后端 未结 2 1823
终归单人心
终归单人心 2020-11-27 18:09

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

2条回答
  •  长情又很酷
    2020-11-27 18:19

    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
    ...
    

提交回复
热议问题