Given this text:
25% on $53,501 to $78,100.
This regex captures the 3 numbers into the three capturing groups (as expected)
^(\d+\.?\d+).*?(\d+,?\d+).*?(\d+,\d+)?.$
However, I would expect this regex to match all 3 groups as well, but the 3rd group is empty.
^(\d+\.?\d+).*?(\d+,?\d+).*?(\d+,\d+)?.*$
The only difference between the first and second regex is that while the first one ends with .$, the second one ends with .*$.
Granted that the second regex can be satisfied without matching anything to the third group, but I would expect the ? in (\d+,\d+)? to match the pattern zero or one times, but one time preferably as it is greedy. In that case the last .* matches nothing, and the whole regex should still be satisfied.
So, why does the regex engine "skip over" the third group and prefer to match the rest of the string with the .*?