ag4ve has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regex help
by locked_user sundialsvc4 (Abbot) on Jun 28, 2012 at 15:46 UTC | |
|
Re: regex help
by aaron_baugher (Curate) on Jun 28, 2012 at 13:22 UTC | |
by ag4ve (Monk) on Jun 28, 2012 at 13:36 UTC | |
by ag4ve (Monk) on Jun 28, 2012 at 13:46 UTC | |
by aaron_baugher (Curate) on Jun 28, 2012 at 14:23 UTC | |
by ag4ve (Monk) on Jun 29, 2012 at 13:17 UTC | |
by ag4ve (Monk) on Jul 02, 2012 at 15:44 UTC |