[Tutor] Global Regular Expressions?
Brian Wisti
bwisti@hotmail.com
Fri, 19 May 2000 13:23:33 PDT
Hi all,
I'm sure that this is just staring me in the face, but I can't figure out
how to step through a string with a regular expression. I know how I want
to do this in Perl. How about I show you what I mean in Perl?
-- Perl Code --
#!/usr/bin/env perl
# A simple example of the strings I'm looking at.
my $string = "<td>item1</td> <td>item2</td><td>item3</td>";
# Find the text within each table cell, and show each match
while ($string =~ m!<td>(.+?)</td>!g) {
print "Matched: ", $1, "\n";
}
print "All done!\n";
-- End of Code --
So how do I say it in Python? Would I be able to use a while loop, or is
there some other construct (splitting, or whatever) that I should be using?
Thanks ahead of time for any ideas,
Brian Wisti
bwisti@hotmail.com
________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com