I have a regex
.*?(\\d+.*?\\d*).*?-.*?(\\d+.*?\\d*).*?
I want to match any string that contains a numerical value followed by "-" and another number. Any string can be in between.
Also, I want to be able to extract the numbers using group function of Java Matcher class.
Pattern pattern = Pattern.compile(".*?(\\d+.*?\\d*).*?-.*?(\\d+.*?\\d*).*?");
Matcher matcher = pattern.matcher("13.9 mp - 14.9 mp");
matcher.matches();
I expect this result:
matcher.group(1) // this should be 13.9 but it is 13 instead
matcher.group(2) // this should be 14.9 but it is 14 instead
Any idea what I am missing?
\d+.*\d*or better, use\d+(?:\.\d+)?