Sunday, 15 September 2013

regex - Range 1 to 9223372036854775807 with regular expression -



regex - Range 1 to 9223372036854775807 with regular expression -

i trying working , there not quite!

i need able allow range 1 9223372036854775807.

i have next regex:

^([1-9][0-9]{0,18}|9223372036854775807)$

that allows me come in values in range want, allows go 9999999999999999999 easy block go 9223372036854775807?

don't utilize regex. it's inefficient, , way worse integer parsing logic can ever write.

for sake of demonstration, here go:

class="lang-regex prettyprint-override">^(?:[1-9][0-9]{0,17}|[1-8][0-9]{18}|9(?:[01][0-9]{17}|2(?:[01][0-9]{16}|2(?:[0-2][0-9]{15}|3(?:[0-2][0-9]{14}|3(?:[0-6][0-9]{13}|7(?:[01][0-9]{12}|20(?:[0-2][0-9]{10}|3(?:[0-5][0-9]{9}|6(?:[0-7][0-9]{8}|8(?:[0-4][0-9]{7}|5(?:[0-3][0-9]{6}|4(?:[0-6][0-9]{5}|7(?:[0-6][0-9]{4}|7(?:[0-4][0-9]{3}|5(?:[0-7][0-9]{2}|80[0-7]))))))))))))))))$

instead, parse integer using standard libraries of language working in, , utilize value checks instead (> operators, et cetera).

regex

No comments:

Post a Comment