I’m trying to remove unused spans (i.e. those with no attribute) from HTML files, having already cleaned up all the attributes I didn’t want with other regular expressions.
I’m having a problem with my regex not picking the correct pair of start and end tags to remove.
my $a = 'a <span>b <span style='color:red;'>c</span> d</span>e'; $a =~ s/<span\s*>(.*?)<\/span>/$1/g; print '$a\
returns
a b <span style='color:red;'>c d</span>e
but I want it to return
a b <span style='color:red;'>c</span> de
Help appreciated.
Try HTML::Parser: