in reply to Pattern Match Problem
Notes:#!/usr/bin/perl -wl use strict; while (<DATA>) { my $wanted; if (($wanted) = $_ =~ m/^gif"><\/td><td>(?:<b>)?([A-Z0-9\(\)\[\]]+ +?)<\/td>/) { print $wanted; } } __DATA__ gif"></td><td>XXX</td></tr> gif"></td><td>XXX</td></tr> gif"></td><td><b>XXX</td><td><b>yyy</td></tr>
- makes the <b> optional, and doesn't capture it(?:<b>)?
- is where you capture your wanted string. Note the trailing +? - this makes it non-greedy, so that it only captures up until the first </td>([A-Z0-9\(\)\[\]]+?)
Having said the above, be aware that there are several CPAN modules available for parsing HTML.
Hope this helps,
Darren :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Pattern Match Problem
by Anonymous Monk on Mar 20, 2006 at 12:22 UTC | |
by ayrnieu (Beadle) on Mar 21, 2006 at 22:34 UTC |