正则表达式 – 如何匹配小于或等于100的数字?

前端之家收集整理的这篇文章主要介绍了正则表达式 – 如何匹配小于或等于100的数字?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
嗨,我想匹配小于或等于100的数字,它可以是0-100之内的任何值,但正则表达式不应匹配大于100的数字,如120 130,150,999等.
尝试这个
\b(0*(?:[1-9][0-9]?|100))\b

说明

"
\b                # Assert position at a word boundary
(                 # Match the regular expression below and capture its match into backreference number 1
   0              # Match the character “0” literally
      *           # Between zero and unlimited times,as many times as possible,giving back as needed (greedy)
   (?:            # Match the regular expression below
                  # Match either the regular expression below (attempting the next alternative only if this one fails)
         [1-9]    # Match a single character in the range between “1” and “9”
         [0-9]    # Match a single character in the range between “0” and “9”
            ?     # Between zero and one times,giving back as needed (greedy)
      |           # Or match regular expression number 2 below (the entire group fails if this one fails to match)
         100      # Match the characters “100” literally
   )
)
\b                # Assert position at a word boundary
"

访问here以备将来出现问题.

猜你在找的正则表达式相关文章