import re data = "ahahahttp://www.google.com/a.jpg>hhdhd" print re.match(r'(ftp|http)://.*.(jpg|png)$', data)