Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 我想做一个正则表达式,它将匹配最多3位可选的,在开始时有四个字,最多一个字,最少一个字,后面有空格_Regex - Fatal编程技术网

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}$

正则表达式详细信息:

  • ^
    :开始
  • (?:\d{1,3}\h+)
    :匹配1到3位数字,后跟1+空格。此组是可选的匹配项
  • \D\S*
    :匹配必须以非数字开头的1+非空格单词
  • (?:\h+\S+{0,3}
    :匹配1+空格,后跟1+非空格单词。将此非捕获组的0与3匹配
  • $
    :结束

它允许3个以上不正确的数字。它不匹配
1450这是一个学校吗
line但是如果数字后面没有单词,它应该返回false。如何防止它接受每边有一个空格的一个字母(一个字母单词)?我的意思是每个单词的字母限制应该超过一个字母。示例:这是一个School=false这是School=true只需使用
^(?:\d{1,3}\h+)\d\S*(?:\h+\S{2,}){0,3}$