regexp question

J

Jabba Laci

Hi,

How to find all occurences of a substring in a string? I want to
convert the following Perl code to Python.

Thanks,

Laszlo

==========

my $text = '<a href="ad1">sdqs</a><a href="ad2">sds</a><a href=ad3>qs</a>';

while ($text =~ m#href="?(.*?)"?>#g)
{
print $1, "\n";
}
# output:
#
# ad1
# ad2
# ad3
 
J

Jon Clements

Hi,

How to find all occurences of a substring in a string? I want to
convert the following Perl code to Python.

Thanks,

Laszlo

==========

my $text = '<a href="ad1">sdqs</a><a href="ad2">sds</a><a href=ad3>qs</a>';

while ($text =~ m#href="?(.*?)"?>#g)
{
   print $1, "\n";}

# output:
#
# ad1
# ad2
# ad3

There's numerous threads on why using regexp's to process html is not
a great idea. Search GGs.

You're better off using beautifulsoup (an HTML parsing library). The
API is simple, and for real-world data is a much better choice.

hth
Jon.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,181
Messages
2,570,970
Members
47,537
Latest member
BellCorone

Latest Threads

Top