Wednesday 15 May 2013

python - Improve regular expression to end on quotation -



python - Improve regular expression to end on quotation -

i have next regular expression:

>>> re.findall('http://www.rottentomatoes.com/.+', html) ['http://www.rottentomatoes.com/m/1129132-torque" class="see-all">read more film on rotten tomatoes</a>']

how match until ". trying homecoming be:

http://www.rottentomatoes.com/m/1129132-torque

use non-greedy quantifier ? stop @ first ":

>>> html = 'http://www.rottentomatoes.com/m/1129132-torque" class="see-all">read more film on rotten tomatoes</a>' >>> re.search('(http://www\.rottentomatoes\.com/.+?)"', html).group(1) 'http://www.rottentomatoes.com/m/1129132-torque'

python regex

No comments:

Post a Comment