ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-list
python-list
Re: regexp question
by Jon Clements other posts by this author
Nov 6 2009 2:21PM messages near this date
Re: regexp question | imputil.py, is this a bug ?
On Nov 6, 9:50 pm, Jabba Laci <jabba.l...@[...].com>  wrote:
>  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.
-- 
http://mail.python.org/mailman/listinfo/python-list
Thread:
Jabba Laci
Rami Chowdhury
Jabba Laci
Jon Clements

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved