To match your date format:

m{ # any of the 12 months: (?: January | February | March | April | May | June | July | August | September | October | November | December ) \s # a space between month and day [123]?\d # Is the first day 1, \s1, or 01? , # a comma between day and year \s? # an optional space between comma and year [12]\d{3} # a four digit year }xms

Each \s can match a newline as well as a space. Normally I'd write \s+ and \s* to match multiple spaces and zero-or-more spaces, respectively, but your spec seems to indicate only one is expected. I wasn't sure how a single digit day is to be represented, so I made it a single digit. If it needs a leading zero or space, the pattern needs to account for that.

To match intervening tags, I'd make it like this:

m{ # any of the 12 months: (?: January | February | March | April | May | June | July | August | September | October | November | December ) (?:<.+?>|\s)* # zero or more tag like things or spaces [123]?\d # Is the first day 1, \s1, or 01? , # a comma between day and year (?:<.+?>|\s)* # zero or more tag like things or spaces [12]\d{3} # a four digit year }xms

Note that this allows there to be no space between the month and day.

To extract the date from this, wrap the pattern in parentheses and take it from $1 afterward.

if ( $html =~ m{ ( blah blah as above blah blah ) }xms ) { my $date = $1; # remove the tags, if there are any $date =~ s/<.+?>//g; }

I have not tested any of the above. Hope it helps.


In reply to Re: How to extract information that spans over two lines in HTML by kyle
in thread How to extract information that spans over two lines in HTML by coltman

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.