正则表达式 - 20 个字符长数字(仅带空格)如何

Ayo*_*ina 1 c# regex

我对正则表达式完全没用,我需要做的是定义一个模式,该模式允许字符串至少包含 5 个字符,最多 20 个字符,仅允许空格和数字,不允许 AZ。

有任何想法吗?

hwn*_*wnd 5

您可以使用以下正则表达式:

@"^[\d ]{5,20}$"
Run Code Online (Sandbox Code Playgroud)

解释:

^              # the beginning of the string
 [\d ]{5,20}   # any character of: digits (0-9), ' ' (between 5 and 20 times)
$              # before an optional \n, and the end of the string
Run Code Online (Sandbox Code Playgroud)