Project

General

Profile

Java Pattern group "No matches found"...

Added by Komorek, Kamil 6 months ago

Got regexp and pattern:

final String VALUE_REGEXP = "(\\d+):(\\d+)";
final Pattern VALUE_PATTERN = Pattern.compile(VALUE_REGEXP)

I'm getting "No match found" on below code:
final Matcher matcher = VALUE_PATTERN.matcher(input);
final String number = matcher.group(1);

Solution is to call matcher.matches() before group extraction, like below:
final Matcher matcher = VALUE_PATTERN.matcher(input);

matcher.matches()      // returns boolean, ofc check result...

final String number = matcher.group(1);


Comments