应该接受字母和regex_only一个空格但不能在开头和结尾;没有数字和特殊字符允许 [英] Should accept alphabets and with regex_only one space but not in begin and end; no number and special chars allowed
问题描述
嗨朋友们,
请您为下面提供常规快递。
应该接受字母和只有一个空格但不在开头和结尾;没有数字和特殊字符
以下内容应该通过:
A
AB
Hello There
以下内容应该失败:
A
A
A
测试
我的尝试:
Hi Friends,
Please will you provide regular express for the below.
should accept alphabets and with only one space but not in begin and end; no number and special chars allowed
The following should pass:
"A"
"A B"
"Hello There"
The following should fail:
" A"
"A "
" A "
" test"
What I have tried:
"^([a-zA-Z]+\S{0,1})*[a-zA-Z]+$"
推荐答案
^([a-zA-Z] + \ S {0,1})* [a-zA-Z] +
^([a-zA-Z]+\S{0,1})*[a-zA-Z]+
据我所见,您的RegEx是正确的你需要提供更多关于它如何失败的信息。
只是一些有趣的链接来帮助建立和调试RegEx。
这里是RegEx文档的链接:
perlre - perldoc.perl.org [ ^ ]
以下是帮助构建RegEx并调试它们的工具的链接:
.NET Regex Tester - Regex Storm [ ^ ]
Expresso正则表达式工具 [< a href =http://www.ultrapico.com/expresso.htmtarget =_ blanktitle =New Window> ^ ]
这个显示RegEx作为一个很好的图表,它非常有助于理解RegEx的作用:
Debuggex:在线可视正则表达式测试器。 JavaScript,Python和PCRE。 [ ^ ]
As far as I can see, your RegEx is correct. You need to provide more informaions on how it fail.
Just a few interesting links to help building and debugging RegEx.
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx:
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
这篇关于应该接受字母和regex_only一个空格但不能在开头和结尾;没有数字和特殊字符允许的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!