[wplug] regex help
Brian Medley
bpm-list-wplug at 4321.tv
Mon Jan 12 19:37:10 EST 2004
On Mon, Jan 12, 2004 at 06:45:03PM -0500, James O'Kane wrote:
> > If so, then consider matching the following line:
> >
> > <td>One Cell</td><td>Two Cell</td>
> >
> > I believe that /<td.*?>/ will find "<td>One Cell</td>" and /<td.*>/
> > would match the entire line. Basically, the way I think about it is
> > that w/ greedy the beginning anchor is set as soon as possible and
> > the ending anchor is set as late as possible. With non-greedy, the
> > beginning anchor is the same, but the ending anchor is set as soon as
> > possible.
>
> perl disagrees. # comments after the #'s
>
> [jo2y at dax jo2y]$ perl -de 0 # -d starts the debugger -e 0 executes '0'
>
> Loading DB routines from perl5db.pl version 1.19
> Editor support available.
>
> Enter h or `h h' for help, or `man perldebug' for more help.
>
> main::(-e:1): 0
> DB<1> $|=1 # Turn off IO buffering
>
> DB<2> $string = "<td>One Cell</td><td>Two Cell</td>"
>
> DB<3> $string =~ /(<td.*>)/ ; print $1
> <td>One Cell</td><td>Two Cell</td>
> DB<4> $string =~ /(<td.*?>)/ ; print $1
> <td>
Ack! I must be using an old version of perl in my head...:) That's
what I get for not doing proper testing.
DB<2> x $string =~ /(<td>.*?>)/
0 '<td>One Cell</td>'
So, one possible approach is to change it to /<td>.*?>/. If I had read
my own paragraph about stopping as soon as possible, I would have
realized my own error...:)
--
~'`^`'~=-.,__,.-=~'`^`'~=-.,__,.-=~'`^`'~=-., \|/ (___) \|/ _,.-=~'`^`
@~./'O o`\.~@
"Knowledge is Power" /__( \___/ )__\ *PPPFFBT!*
-- Francis Bacon `\__`U_/'
_,.-=~'`^`'~=-.,__,.-=~'`^`'~=-.,__,.-=~'`^`'~= <____|' ^^`'~=-.,__,.-=
~`'^`'~=-.,__,.-=~'`^`'~=-.,__,.-=~'`^`'~=-.,__,.-==--^'~=-.,__,.-=~'`^`
More information about the wplug
mailing list