结合2个preg比赛。 [英] Combining 2 preg matches.
问题描述
嗨组,
我有一个使用preg匹配验证字符串的函数。
部分看起来像
if(!preg_match(''/ ^([a-z0-9] +(([a-z0-9 _-] *)?[a-z0-9])?)$ /'', $ string)
||
preg_match(''/( - | __)+ /'',$ string)){
i我怎么能把这两者结合成一个......
我尝试了几个不同的选择,将第二场比赛放入
第一场比赛,
使用类似[^ __] +等的东西,但没有什么对我有用。
它应该防止每个背后的双重(或更多)破折号或下划线
其他。
hello-there = ok
你好 - 那里!= ok
任何帮助都会很棒。
Frizzle。
Hi group,
I have a function which validates a string using preg match.
A part looks like
if( !preg_match( ''/^([a-z0-9]+(([a-z0-9_-]*)?[a-z0-9])?)$/'', $string )
||
preg_match( ''/(--|__)+/'' ,$string) ) {
i wonder how i could combine those two into one ...
I tried a few different options of putting the second match into the
first one,
using things like [^__]+ etc, but nothing worked for me.
it should prevent double (or more) dashes or underscores behind each
other.
hello-there = ok
hello--there != ok
Any help would be great.
Frizzle.
推荐答案
/'',
string)
||
preg_match(''/( - | __)+ /'',
string )
||
preg_match( ''/(--|__)+/'' ,
字符串)){$ / $
i wond我怎么能把这两者结合成一个...
我尝试了几个不同的选择,将第二场比赛放入
第一场,
使用类似[^ __] +等的东西,但没有什么对我有用。
它应该防止每个
其他背后的双重(或更多)破折号或下划线。
hello-there = ok
你好 - 那里!= ok
任何帮助都会很棒。
Frizzle。
string) ) {
i wonder how i could combine those two into one ...
I tried a few different options of putting the second match into the
first one,
using things like [^__]+ etc, but nothing worked for me.
it should prevent double (or more) dashes or underscores behind each
other.
hello-there = ok
hello--there != ok
Any help would be great.
Frizzle.
这篇关于结合2个preg比赛。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!