![]() |
|
|
|
#1 |
|
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 Jabba Laci |
|
|
|
|
#2 |
|
Posts: n/a
|
On Nov 6, 9:50*pm, Jabba Laci <jabba.l...@gmail.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. Jon Clements |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Motherboard general question | Jimmy Sledge | Computer Information | 8 | 03-10-2007 08:37 AM |
| Question on learning "Networking"... | DoubleEntendre | Computer Support | 15 | 03-11-2006 11:28 AM |
| hd partition question | rabbit | Computer Support | 6 | 01-12-2006 04:05 AM |
| Wireless PEAP/MSCHAPV2 client programming question | Jim Howard | Wireless Networking | 6 | 07-02-2005 12:53 PM |
| xp question | Barry | Computer Support | 18 | 12-31-2003 06:06 AM |