Regex 我想做一个正则表达式,它将匹配最多3位可选的,在开始时有四个字,最多一个字,最少一个字,后面有空格
Regex 我想做一个正则表达式,它将匹配最多3位可选的,在开始时有四个字,最多一个字,最少一个字,后面有空格,regex,Regex,在此处输入code我想制作一个正则表达式,它将匹配最多3位可选数字,开头最多四个字,后面有空格,最多一个字 ^\d{0,3}\s School This is a School 1 This is a School 145 Is this a School 1450 Is this a School This is Govt Hight School School=True This is a School=True 1 This is a School=True 145 Is this
在此处输入code
我想制作一个正则表达式,它将匹配最多3位可选数字,开头最多四个字,后面有空格,最多一个字
^\d{0,3}\s
School
This is a School
1 This is a School
145 Is this a School
1450 Is this a School
This is Govt Hight School
School=True
This is a School=True
1 This is a School=True
145 Is this a School=True
1450 Is this a School=False
This is Govt Hight School=False
您可以使用此正则表达式:
^(?:\d{1,3}\h+)\d\S*(?:\h+\S+{0,3}$
正则表达式详细信息:
:开始^
:匹配1到3位数字,后跟1+空格。此组是可选的匹配项(?:\d{1,3}\h+)
:匹配必须以非数字开头的1+非空格单词\D\S*
:匹配1+空格,后跟1+非空格单词。将此非捕获组的0与3匹配(?:\h+\S+{0,3}
:结束$
1450这是一个学校吗
line但是如果数字后面没有单词,它应该返回false。如何防止它接受每边有一个空格的一个字母(一个字母单词)?我的意思是每个单词的字母限制应该超过一个字母。示例:这是一个School=false这是School=true只需使用^(?:\d{1,3}\h+)\d\S*(?:\h+\S{2,}){0,3}$