正则表达式的一点帮助 [英] A little Help in Regular Expressions
问题描述
'/ ^ [az,ñ] +(( - |)?[az,ñ] +)+(( - |)?[az,ñ] +)?$ / i'
如果我只输入1个字符,为什么不接受?
'/^[a-z,ñ]+((-| )?[a-z,ñ]+)+((-| )?[a-z,ñ]+)?$/i'
Why doesn't it accept if i only input 1 character?
推荐答案
/ i'
如果我只输入1个字符,为什么不接受?
/i'
Why doesn't it accept if i only input 1 character?
简单:你告诉它不要!
如果我压缩一点可能会更明显一点:
Simple: you have told it not to!
If I compact this a bit it may be a bit more obvious:
^x+y+(z+)?
其中x,y和z是你的正则表达式中的短语。
这需要一个或多个x,然后是一个或更多y,然后一个或多个z - 至少三个字符。
我不知道你到底要做什么,所以我无法开始纠正它,但获得 Expresso 的副本[ ^ ] - 它是免费的,它会检查并生成正则表达式。这将使问题显而易见!
Where x, y, and z are the "phrases" in your regex.
That requires "one or more x", then "one or more y", then "one or more z" - a minimum of three characters.
I don't know exactly what you are trying to achieve, so I can't begin to correct it, but get a copy of Expresso [^] - it's free, and it examines and generates Regular expressions. It will make it pretty obvious what the problem is!
这篇关于正则表达式的一点帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!