Next regex says any optional group of 1 to 3 digits plus any optional group of 4 non-whitespaced chars.
^([\d]{1,3})?(\S{4})?$
My problem is that if I input 444EEE, Java matches it as 44 + 4EEE, instead of, matching first the first group as 444 and exiting because the trailing EEE is not made of 4 chars. So how can I avoid the left-wards greediness of the last group, so the second last consumes first. Is it “?+”
Thank you
Use
The extra
+after the{0,3}quantifier tells the regex engine not to backtrack into the first group (a so-called possessive quantifier).