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

rak*_*los 3 regex

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

我需要它匹配以50.

我有:

^[ ]*(50)[0-9]{7}[ ]*$
Run Code Online (Sandbox Code Playgroud)

允许 9 位数字。

我该如何扩展它以便它也允许 10 位数字?

psx*_*xls 5

添加范围 {7,8}

^[ ]*(50)[0-9]{7,8}[ ]*$
Run Code Online (Sandbox Code Playgroud)

仅供参考,该站点描述了您可以在正则表达式中使用的标准量词:

* 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
Run Code Online (Sandbox Code Playgroud)