regex - 创建一个允许 9 或 10 位数字的正则表达式

标签 regex

我需要正则表达式方面的帮助

我需要它匹配以 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/

相关文章:

regex - 将连字符替换为破折号

java - 我如何在 Java 中过滤掉除单词、数字和一些符号之外的所有内容?

c# - 确定 Regex 对象是否只接受大写字符

javascript - ExtJS - 使用 RegEx 过滤缓冲存储

C - 我可以从 char * 创建一个 const char * 变量吗?

regex - 提取最后一个词/文本多个匹配的 logstash

python - 无法让此正则表达式适用于 Snakemake 中的 wildcard_constraints

python - Unicode 搜索不起作用

javascript - JavaScript 中的 match 是什么意思

ios - 使用 stringByReplacingOccurrencesOfString 来考虑 "words"