I think the img_src regex above is fine, but by now you might as well be using lxml or some such things, no? Also, I think you could make this code clearer by using .format rather than +=