Hi,am trying to search and extract the text


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

import re

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.

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.