Search code examples
regexregexp-replace

Regexp for checking if number is above 10


Need to check if given number is above 10. With regular expression. Not with pl. Number is positive integer without leading zeroes and without plus sign in a string format. This code neeeded for replacing quantities above 10 with '10+'

Tested two answers with 1 mil runs on same numbers:

^(?!10$)[1-9]\d+$ - 5.373779535293579 sec

^(?:1[1-9]|[2-9]\d|\d{3,})$ - 1.5149388313293457 sec


Solution

  • Sounds like a simple enough matter:

    ^(?:1[1-9]|[2-9]\d|\d{3,})$