mardi 25 février 2020

java regex greedy match results in truncated group

I'm parsing a file and looking for a pattern of 3 or 4 digits followed by a hyphen followed by 3 or 4 digits (123 - 123, 123 - 1234, 1234 - 123, 1234 - 1234).

I'm using this Pattern: (\\d{3,4} - \\d{3,4})

I am able to find the various permutations but when I retrieve the group, it is missing the first digit. For example, if I find '1234 - 1234', then matcher.group(1) returns '234 - 1234'

Aucun commentaire:

Enregistrer un commentaire