[英]Simple preg match pattern
Please can someone help me out with the expression required for the following: 请有人帮我解决以下问题:
A $content variable holds a block of HTML and I want to match it against a string that could contain any ID. $ content变量包含一个HTML块,我想将其与可能包含任何ID的字符串匹配。 So I am looking for <p>###GALLERY(ANY NUMBER HERE)###</p>
所以我正在寻找<p>###GALLERY(ANY NUMBER HERE)###</p>
This is the code I have already that doesn't work (sorry new to regex): 这是我已经无法使用的代码(对不起,正则表达式很新):
if (preg_match("<p>###GALLERY[0-9]###</p>", $content))
{
// Found
}
Any help would be greatly appreciated. 任何帮助将不胜感激。
You need to include delimiters in your expression: 您需要在表达式中包括定界符 :
if (preg_match("/<p>###GALLERY[0-9]###<\/p>/", $content))
I'm not sure if you need this, but adding a +
quantifier after [0-9]
will allow for multi-digit numbers: 我不确定您是否需要这样做,但是在[0-9]
之后添加+
量词将允许多位数:
if (preg_match("/<p>###GALLERY[0-9]+###<\/p>/", $content))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.