需要一些regex帮助来创建regex newb。
如果我们的URL包含
SearchBox.
(SearchBox,末尾有点)或
SearchBox-Empty
然后,我们需要做点什么。因此,匹配URL的示例是:
http://www.thesite.com/SearchBox.html
或http://www.thesite.com/SearchBox-Empty.html
不匹配的URL是:
http://www.thesite.com/SearchBox-Function.html
所以,我只想在没有调用函数的情况下匹配它。
以下是我目前所拥有的:
if((preg_match("@SearchBox'.@",$_SERVER['REQUEST_URI']) || preg_match("@SearchBox'-Empty@",$_SERVER['REQUEST_URI'])) && !empty($_REQUEST['ID']) && is_numeric($_REQUEST['ID'])) {
谢谢你的帮助!
如果我没记错,你需要转义反斜杠:
"/SearchBox(?:''.|-Empty)/"
试试这个代码:
if(preg_match("/(SearchBox|SearchBox'-Empty)'.html$/",$_SERVER['REQUEST_URI']) && is_numeric($_REQUEST['ID'])) {
//...
}
试试这个正则表达式-我不太熟悉PHP正则表达式的风格,但:
preg_match("/SearchBox(''.|''-Empty''.html)[.]*/",$_SERVER['REQUEST_URI'])