I need a RegEx for a numeric value with up to 2 decimals places that allows for all numbers over 60 but none below.
I have used the below RegEx for numbers between 0 and 60, but now I need a similar expression for all numbers over 60
^(?=.)(?:(?:(?:0|[1-5]?\d)?(?:[,.]\d{1,2})?)|60(?:[.,]00?)?)$
CodePudding user response:
You can use
^(?!60(?:\.00?)?$)(?:[6-9][0-9]|[1-9][0-9]{2,})(?:\.[0-9]{1,2})?$
Or, if you cannot afford lookaheads:
^(?:60(?:\.(?:0?[1-9]|[1-9][0-9]))|(?:6[1-9]|[7-9][0-9]|[1-9][0-9]{2,})(?:\.[0-9]{1,2})?)$
See the regex demo #1 / regex demo #2.
Details:
^- start of string(?!60(?:\.00?)?$)- a negative lookahead that fails the match if the string is60,60.0or60.00(?:- start of a non-capturing group:[6-9][0-9]-60to99number|- or[1-9][0-9]{2,}- a digit from1to9and then two or more digits (100and more)
)- end of the group(?:\.[0-9]{1,2})?- an optional sequence of a.and one or two digits$- end of string.
