in reply to Background color HTML regexp
Three little things, beyond what's said above: you might want to look at CPAN modules for dealing for CSS. They'll parse a bit of CSS for you and then let you get hold of the background-color attributes using a hash. Too easy!
You probably don't need the brackets round "background" and "color" in your regexp. The brackets will make perl remember what it found inside those brackets and store it in the $1 and $2 variables. That's probably a bit wasteful unless you need it.
Finally, it's valid CSS to have 3 characters rather than 6 specifying a hex colour value. See colour units in the CSS spec. Also, CSS is (mostly) case insensitive, so you probably want to match BACKgrouNd-CoLoR as well. Well, here's a slightly modified version:
if ( $css =~ /background-color\s*:\s*#([0-9a-f]{6}|[0-9a-f]{3})\s*;?/i + ) { print "background color is $1"; }
HTH
ViceRaid
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Background color HTML regexp
by Tricky (Sexton) on Aug 23, 2003 at 09:21 UTC |