我需要正则表达式方面的帮助
我需要它匹配以 50
开头的 9 位或 10 位数字值.
我有:
^[ ]*(50)[0-9]{7}[ ]*$
允许 9 位数字。
我该如何扩展它以便它也允许 10 位数字?
最佳答案
添加范围 {7,8}
^[ ]*(50)[0-9]{7,8}[ ]*$
仅供引用 this site描述了可以在正则表达式中使用的标准量词:
* Match 0 or more times
+ Match 1 or more times
? Match 1 or 0 times
{n} Match exactly n times
{n,} Match at least n times
{n,m} Match at least n but not more than m times
关于regex - 创建一个允许 9 或 10 位数字的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19138172/