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

p = re.compile(r'(href="(.*?)")')

will do the trick

Thanks you so much.

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')

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.