当前位置: 动力学知识库 > 问答 > 编程问答 >

pcre - MyBB - PHP regex

问题描述:

I have the following regex.

\[rep=([0-9]*?),([0-9]*?)\]([\w#]{4,11}),([\w#]{4,11}),([\w#]{4,11}),([\w#]{4,11})\[\/rep\]

To me this seems perfectly valid - it's meant to match for instance the following string:

[rep=0,20]#fff,#fff000,#111,transparent[/rep]

And while it does seem to work in, for instance, RegExr, the MyCode for it just doesn't seem to trigger.

网友答案:

I found the issue. The hashes # had to be escaped.

\[rep=([0-9]*?),([0-9]*?)\]([\w\#]{4,11}),([\w\#]{4,11}),([\w\#]{4,11}),([\w\#]{4,11})\[\/rep\]

网友答案:

It looks like you're not putting the delimiters in your PHP implementation.

if( preg_match("/\[rep=([0-9]*?),([0-9]*?)\]([\w#]{4,11}),([\w#]{4,11}),([\w#]{4,11}),([\w#]{4,11})\[\/rep\]/", $str) ) {

}

https://eval.in/568814

分享给朋友:
您可能感兴趣的文章:
随机阅读: