in reply to Using a Regex to parse into keys
$_ = qq{<html><foo>4~<font color="#FF0000"><b>,</b></font><fush> 5~ <fish>#555555<>6~ <font #444444>}; print "$_\n"; my %colours = (m!(\d+)~\s*<\s*font\s+[^#]*(#[A-F0-9]{6})!igs); print $colours{4}; # will print #FF0000
This code will handle (some cases where) '#' appears elsewhere and will ignore any case where the colour does not contain 6 hex digits. It's case insensitive, and allows spaces all over the place. I still hope that you have some idea of your expected data, as there are many cases that this can still break.
Hope it helps.
jarich
Update: mdillon pointed out a copy error. Was @colours, needed to be %colours.
|
|---|