[英]PCRE regex and spaces
I'm working on this regex: 我正在研究此正则表达式:
/\{(\w+)::(\w+)::([\sa-zA-Z0-9]+)\}/
So, from a long string, I could get patterns like: Word::Word::Word and word and word 因此,从一个长字符串中,我可以得到如下模式:Word :: Word :: Word和word和word
I've tested this regex here: http://regex101.com/ 我已经在这里测试过此正则表达式: http : //regex101.com/
And in PHP it sais it should work fine. 在PHP中,它说应该可以正常工作。
But when I put into code, it doesn't work: 但是当我输入代码时,它不起作用:
$pattern = '/\{(\w+)::(\w+)::([\sa-zA-Z]+)\}/';
echo preg_match_all(preg_match_all($pattern,'{WORD::WORD::PRUEB ASDF ASD}', $expr,PREG_PATTERN_ORDER));
the echo result is 0 回声结果为0
You are calling preg_match_all inside preg_match_all. 您正在调用preg_match_all中的preg_match_all。 Do this instead:
改为这样做:
$pattern = '/\{(\w+)::(\w+)::([\sa-zA-Z]+)\}/';
echo preg_match_all($pattern,'{WORD::WORD::PRUEB ASDF ASD}', $expr, PREG_PATTERN_ORDER);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.