Regex 正在查找名称年龄性别的正则表达式,中间必须有空格
这就是我所拥有的,但它不起作用。我没有犯错误,但我也没有得到结果,通过或失败Regex 正在查找名称年龄性别的正则表达式,中间必须有空格,regex,Regex,这就是我所拥有的,但它不起作用。我没有犯错误,但我也没有得到结果,通过或失败 ^[a-zA-Z]+(([\'\ \][(^10$|^[0-9]{1,2}]))+(([\'\ \][(?:m|M|f|F|)$]))*$ 首先,让我们看看您提到的模式将匹配什么: ===================================================================== ^[a-zA-Z]+(([\'\ \][(^10$|^[0-9]{1,2}]))+(([\'\ \
^[a-zA-Z]+(([\'\ \][(^10$|^[0-9]{1,2}]))+(([\'\ \][(?:m|M|f|F|)$]))*$
首先,让我们看看您提到的模式将匹配什么:
=====================================================================
^[a-zA-Z]+(([\'\ \][(^10$|^[0-9]{1,2}]))+(([\'\ \][(?:m|M|f|F|)$]))*$
=====================================================================
Assert position at the beginning of the string «^»
Match a single character present in the list below «[a-zA-Z]+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
A character in the range between “a” and “z” «a-z»
A character in the range between “A” and “Z” «A-Z»
Match the regular expression below and capture its match into backreference number 1 «(([\'\ \][(^10$|^[0-9]{1,2}]))+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Note: You repeated the capturing group itself. The group will capture only the last iteration. Put a capturing group around the repeated group to capture all iterations. «+»
Match the regular expression below and capture its match into backreference number 2 «([\'\ \][(^10$|^[0-9]{1,2}])»
Match a single character present in the list below «[\'\ \][(^10$|^[0-9]{1,2}»
Between one and 2 times, as many times as possible, giving back as needed (greedy) «{1,2}»
A ' character «\'»
A character «\ »
A ] character «\]»
One of the characters “[(^10$|” «[(^10$|^[»
A character in the range between “0” and “9” «0-9»
Match the character “]” literally «]»
Match the regular expression below and capture its match into backreference number 3 «(([\'\ \][(?:m|M|f|F|)$]))*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
Note: You repeated the capturing group itself. The group will capture only the last iteration. Put a capturing group around the repeated group to capture all iterations. «*»
Match the regular expression below and capture its match into backreference number 4 «([\'\ \][(?:m|M|f|F|)$])»
Match a single character present in the list below «[\'\ \][(?:m|M|f|F|)$]»
A ' character «\'»
A character «\ »
A ] character «\]»
One of the characters “[(?:m|MfF)$” «[(?:m|M|f|F|)$»
Assert position at the end of the string (or before the line break at the end of the string, if any) «$»
很明显,该模式希望与上下文相匹配,如:
aaaa' ]'m
当您要匹配类似于bob33m
的内容时,最简单的模式是:
(?i)^[a-z]+ [0-9]+ [mf]+$
也就是说
希望此能够帮助您理解主题。如果我们没有关于输入、预期输出和您当前获得的输出的信息,我们无法真正帮助您。“它不工作”根本不是一个有用的问题描述。请使用此信息更新您的问题。非常感谢。再补充一句,你现在的表达显然是在寻找比“姓名年龄性别”更多的废话,所以输入行的例子是必不可少的。谢谢你的回答。基本上,我正在尝试在我的表单中创建一个字段来捕获姓名(最好是任何名字“a-z”,然后是一个一位数或两位数的年龄“0-9”,最后是“m”或“f”或“m”或“f”)。我更希望正则表达式在每个条件之间强制留一个空白。因此…Bob 33 M对不起,不工作的部分意味着在正则表达式测试仪中测试时,即使输入正确的模式,它也不会显示任何匹配。非常感谢Cylian!你不仅解释了正则表达式的一些工作,而且还帮助我完成了co德也是。你太棒了。我刚刚发现了一件事。我可以启用它来匹配由回车分隔的一行或多行吗?我已经尝试过了,但它只使用第一行(?I)^[a-z]+[0-9]+[mf]+\s$@user1756546:当然只要使用
(?im)^[a-z]+[0-9]+[mf]+\s$
取而代之。非常感谢塞利安!我要试一试。。。
"(?i)" & ' Match the remainder of the regex with the options: case insensitive (i)
"^" & ' Assert position at the beginning of the string
"[a-z]" & ' Match a single character in the range between “a” and “z”
"+" & ' Between one and unlimited times, as many times as possible, giving back as needed (greedy)
"\ " & ' Match the character “ ” literally
"[0-9]" & ' Match a single character in the range between “0” and “9”
"+" & ' Between one and unlimited times, as many times as possible, giving back as needed (greedy)
"\ " & ' Match the character “ ” literally
"[mf]" & ' Match a single character present in the list “mf”
"+" & ' Between one and unlimited times, as many times as possible, giving back as needed (greedy)
"$" ' Assert position at the end of the string (or before the line break at the end of the string, if any)