Okay, putting aside the arguments that HTML is rarely well formed and that regexps aren't the answer when you can't guarantee the purity of your data etc (ie use HTML::Parser), an answer to your question is as follows:
$_ = 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.


In reply to Re: Using a Regex to parse into keys by jarich
in thread Using a Regex to parse into keys by Kage

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.