Can someone please help me parse text like the lines below? I could use a few splits but it would be messy. I know there is a way to parse the entire line in one command using regex and $1, $2 etc. I would like to get the generic name, dosage which might be an int or an int with text attached to it. The tablet, capsule, injection, and the instructions at the end. I know it's simple but I have not done much perl since 2006. Thanks. Input:
"<h3>FENTANYL 25MCG/HR PATCH, TRANSDERMAL 72 HOURS</h3> <p class='cd1' +>Restricted to NDC labeler code 50458 (Janssen) and to a maximum of t +en (10) transdermal patches per dispensing and a maximum of three (3) + dispensings of any strength in a 75-day period only. </p><p>mfg code +s:50458</p><p>DURAGESIC</p> ", "<h3>ACETAMINOPHEN 80MG/0.8ML SUSPENSION, DROPS(FINAL DOSAGE FORM)(ML) +</h3> <p class='cd1'>Restricted to individuals younger than 21 years +of age for the liquid and drops only. </p><p>mfg codes:68016, 63868, +63162, 49348, 46122, 36800, 00904, 00536, 00472, 00113, 00067</p><p>T +RIAMINIC FEVER REDUCER | PAIN & FEVER | NORTEMP | MAPAP INFANT | INFA +NTS' NON-ASPIRIN | INFANT'S PAIN RELIEVER | INFANT'S PAIN RELIEF | IN +FANT'S NON-ASPIRIN | ACETAMINOPHEN</p> "} <code> foreach my $line(@lines){ print "\n"; # print "My line is $line\n"; # if($line =~ m/\<h3\>(.*)\<\/h3/) { # prints data that is b +etween the <h3> tags if($line =~ m/\<h3\>(.*)\d+(.*)/ ) { print "GENERIC_NAME is: " . $1 . "\n"; # #if ($line =~ m/\d+(.*)/){ ### Does not work. It gets t +he heading tag <h3> # print "Dosage is: " . $1 . "\n"; # } if($line =~ m/\<p class='cd1\'\>(.*)\<\/p\>/) { print "Instructions 2 are: " . $1 . "\n"; } } }
Output
GENERIC_NAME is: FENTANYL 25MCG/HR PATCH, TRANSDERMAL 72 HOURS</h3> <p + class='cd1'>Restricted to NDC labeler code 50458 (Janssen) and to a +maximum of ten (10) transdermal patches per dispensing and a maximum +of three (3) dispensings of any strength in a 75-day period only. </p><p>mfg c +odes:5045 Instructions 2 are: Restricted to NDC labeler code 50458 (Janssen) and + to a maximum of ten (10) transdermal patches per dispensing and a ma +ximum of three (3) dispensings of any strength in a 75-day period onl +y. </p>< p>mfg codes:50458</p><p>DURAGESIC

In reply to parsing a line with $1, $2, $3 by kevyt

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.