I had help creating a regex to get data out of some text documents (please don't comment about parsing html with regex - the resources aren't really html). The regex I have that works for 90% of the documents is:

($match{PAGE}, $match{DESC}) = $text =~ /\[Pages? ([\d-]+).*\n\n(.*?)\n\nAGENCY/s;

However, a few documents don't have an 'AGENCY' section. For instance <link>http://www.gpo.gov/fdsys/pkg/FR-2012-02-03/html/2012-2363.htm</link> fails this regex match for this reason. What I want from this document is:

Commercial Leasing for Wind Power Development on the Outer Continental Shelf (OCS) Offshore Virginia--Call for Information and Nominations

I can't depend on \\.*\\n+ - there isn't always a 'Docket' or other number above. I've tried:

/\[Pages? ([\d-]+).*\n\n(.*?)\n\n(?:AGENCY|ACTION)/s

/\[Pages? ([\d-]+).*\n\n(.*?)\n\n[A-Z]:/s

I've tried splitting this up into two regexes and so on. For more examples: <link>http://www.gpo.gov/fdsys/browse/collection.action?collectionCode=FR</link>. Also, I'm not adverse to different ideas to get the data I want than searching for the section that comes after the paragraph that I'm interested in.


In reply to regex help by ag4ve

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.