I have an expression
^(((\d{1,2}))|((\d{1,2}\.\d{1,2}))|((\d{1,2}\.\d{1,2}\.\d{1,2})))(;?)$
to validate a text line like these:
9
99
99.9
99.99
99.99.9
99.99.99
Now I need to validate all these possible variants for ;-separated text
When I use an expression:
^(((((\d{1,2}))|((\d{1,2}\.\d{1,2}))|((\d{1,2}\.\d{1,2}\.\d{1,2})))(;?))+?)$
It becomes greedy and allows more than 2 digits.
Sorry guys, I need to add some explanations. This is an example of all possible matches
9;99;99.9;99.99;99.99.9;99.99.99
Your problem isn’t caused by greedy matching, but by the fact that you allow the separating semicolon only optionally. I’d try something like (given
dotted_numberis regex that matches your original single value, no semicolon)In the end, it would look like
Or you could perenthesize it the other way around, which may be slightly faster
Even this works: