[英]PHP regular expression with a specific word _my_separator_
Please I have I want to use regex to preg_match this kind of string : 请让我使用正则表达式来preg_match这种字符串:
$liste = 'bla0bla-__my_separator_-01blabla';
I've tried : 我试过了 :
if(preg_match('/^[a-zA-Z0-9]_my_separator_[a-zA-Z0-9]$/', $liste))
echo 'ok';
else echo 'not ok';
But this returns always not ok . 但这返回总是不好 。
Please masters any advise ? 请高手任何指教?
PS : I think that the problem is the _ and the - that what I've tried does not support ! PS:我认为问题是_和-我尝试过的内容不支持!
Thanks in advance. 提前致谢。
将您的正则表达式模式更改为此:
'/^[a-zA-Z0-9_\-]+?_my_separator_[a-zA-Z0-9_\-]+?$/'
You're missing the repeater +
and -
and _
in your whitelists: 您在白名单中缺少中继器
+
和-
和_
:
/^[a-zA-Z0-9\\-_]+_my_separator_[a-zA-Z0-9\\-_]+$/
Your orignal regex would match things like: 您的原始正则表达式将匹配以下内容:
A_my_seperator_B
0_my_seperator_C
but not: 但不是:
AB_my_seperator_C
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.