没有前导零的数字的正则表达式 [英] Regular expression for numbers without leading zeros

查看:35
本文介绍了没有前导零的数字的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个正则表达式来匹配从 0 到 99 的任何数字.可能不包括前导零,这意味着 f.ex.05 不允许.

I need a regular expression to match any number from 0 to 99. Leading zeros may not be included, this means that f.ex. 05 is not allowed.

我知道如何匹配 1-99,但不包括 0.

I know how to match 1-99, but do not get the 0 included.

我的 1-99 正则表达式是

My regular expression for 1-99 is

^[1-9][0-9]?$

推荐答案

更新:

^([0-9]|[1-9][0-9])$

匹配 0-99.不匹配带前导零的值.根据您的应用程序,您可能需要对括号和 或 符号进行转义.

Matches 0-99. Doesn't match values with leading zeros. Depending on your application you may need to escape the parentheses and the or symbol.

这篇关于没有前导零的数字的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆