in reply to How do I extract all text around a keyword between two symbols?

This works assuming you want quick and dirty rather than using the elegant reliable Parser solution.

$string =<<'TEXT'; <tr>1 The last company to fail was ISTF with losses of $60M.</tr> <tr>2 The last company to fail was ITF with losses of $60M.</tr> <tr>3 The last company to fail wasISTF with losses of $60M.</tr> < tr>4 The last company to fail was ISTF with losses of $60M.</tr > TEXT print "Found $1\n" while $string =~ m|<\s*tr\s*>([^<]*\bISTF\b[^<]*)<\ +s*/tr\s*>|gi;

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

  • Comment on Re: How do I extract all text around a keyword between two symbols?
  • Download Code

Replies are listed 'Best First'.
Re: Re: How do I extract all text around a keyword between two symbols?
by Hofmator (Curate) on Aug 01, 2001 at 16:31 UTC

    I'd say that's a little bit too quick and dirty, it breaks easily on sth like: <tr>The <em>last</em> company to fail was ISTF.</tr> Parsing HTML is tricky, that's what the parser modules (mentioned multiple times in this thread) are for.

    -- Hofmator