I want to combine two regular expressions in to one.
$exp1 =/<area.*?href="([^"]*)".*?[^>]*>/s;
$exp2=/<a.*?href="([^"]*)".*?[^>]*>/s';
I want to combine two regular expressions in to one.
$exp1 =/<area.*?href="([^"]*)".*?[^>]*>/s;
$exp2=/<a.*?href="([^"]*)".*?[^>]*>/s';
First of all, I would seriously consider using a proper HTML parser before even touching these kinds of expressions.
That said, what you're after is probably this:
/<(?:a|area).*?href="([^"]*)".*?[^>]*>/s
The (?:a|area)
expression is an alternation between a
and area
; it's wrapped inside (?: ... )
to group the alternation and treat it as a non-capturing subpattern.
See also: subpatterns, alternation
I think this should do it:
$exp =/<(?:area|a).*?href="([^"]*)".*?[^>]*>/s;
Btw, it's a bad idea to attempt to parse [X]HTML with regex.