0

Hi,am trying to search and extract the text

href="http://www.yahoo.com"

from a string
<a href="http://www.yahoo.com" id="link1">.Here is my code:

import re

p=re.compile(r'\b(href="(.*)"){1}\b')
m=p.search('<a href="live.net" link="go2">')
print m.group()

#Prints: href="live.net" link="

The code above

Prints: href="live.net" link="

,but i want to the href="live.net"
I need help on this please

3
Contributors
3
Replies
5
Views
8 Years
Discussion Span
Last Post by jice
0

You should use "*?" instead of "*" : * will take the longest string that match the pattern while *? will take the shortest.
p=re.compile(r'\b(href="(.*?)"){1}\b')

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.