Why not just do an alternation? (At least in this case.)
'#^http://(?:a\.com/id|b\.com/v)_(\w*?)\.html$#'
That's one preg_match
, and zero strstr
s.
Also, not that it is a big danger in this case, but escaping the dots when they should be dots is generally a good idea; your regexp will match "http://bacom/v_id_xhtml"
(with "id_"
captured by (\w*?)
).
If you can't make "one pattern that fits all" (and it's actually a bad idea if you have many options, because your legibility goes down the drain), use a pattern to extract the site name, then do a switch
on it. It will then just be two preg_match
es, and zero strstr
s, no matter how many patterns you have.