Corrected the lack of if(matcher.matches()) before checking the matched groups.