I often find that what starts out as an apparently trivial task of parsing apparantly trivial HTML ends up being very difficult.

Even in this case I would reach for an HTML parser.

#!/usr/bin/perl use warnings; use strict; use HTML::TokeParser::Simple; my @array = <DATA>; for my $line (@array){ my $tp = HTML::TokeParser::Simple->new(\$line); my $cell_data; while (my $t = $tp->get_token){ $cell_data++, next if $t->is_start_tag('td') and $t->get_attr('height') == 40 and $t->get_attr('width') == 40 and $t->get_attr('border') == 0; print $t->as_is if $cell_data and $t->is_text; } } __DATA__ <td width='10' height='40' border='0'>cell data 1</td> <td width='20' height='40' border='0'>cell data 2</td> <td width='30' height='40' border='0'>cell data 3</td> <td width='40' height='40' border='0'>cell data 4</td> <td width='40' height='40' border='0'>cell data 5</td> <td width='40' height='40' border='0'>cell data 6</td> <td width='40' height='40' border='0'>cell data 7</td> <td width='40' height='40' border='0'>cell data 8</td>
Output:

---------- Capture Output ---------- > "C:\Perl\bin\perl.exe" _new.pl cell data 4 cell data 5 cell data 6 cell data 7 cell data 8 > Terminated with exit code 0.

I believe this gives you greater flexibility/adaptability and, for me, is quicker to write. :-)

Hope that helps


In reply to Re: Help constructing a regex that also matches hyphens and parentheses by wfsp
in thread Help constructing a regex that also matches hyphens and parentheses by Anonymous Monk

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.