RegEx - 如果我们的网站URL包含此,那么

need some regex help for a regex newb.

If our URL contains

SearchBox. 

(SearchBox with the dot on the end) or

SearchBox-Empty

Then, we need to do something. So example matching URLs would be:

http://www.thesite.com/SearchBox.html

or http://www.thesite.com/SearchBox-Empty.html

And a non-matching URL would be:

http://www.thesite.com/SearchBox-Function.html

So, I only want it to be matched when there is not a function being called.

Here is what I have so far:

if((preg_match("@SearchBox\.@",$_SERVER['REQUEST_URI']) || preg_match("@SearchBox\-Empty@",$_SERVER['REQUEST_URI'])) && !empty($_REQUEST['ID']) && is_numeric($_REQUEST['ID'])) {

Thanks for your help!

If I recall correctly, you need to escape your backslashes:

"/SearchBox(?:\\.|-Empty)/"

Try this code:

if(preg_match("/(SearchBox|SearchBox\-Empty)\.html$/",$_SERVER['REQUEST_URI']) && is_numeric($_REQUEST['ID'])) {
//...
}

Try this regex - I'm not too familiar with PHP regex flavour but:

preg_match("/SearchBox(\\.|\\-Empty\\.html)[.]*/",$_SERVER['REQUEST_URI'])