You needed to include the re.DOTALL (== re.S) flag to allow the . to match newline (\n).
However, that returns the entire document if "logo" appears anywhere in it; not terribly useful.
Slightly better is
import re html = """ <a href="#"> <img src="logo.png" alt="logo" width="100%" /> </a> """ match_logo = re.compile(r'<[^<]*logo[^>]*>', flags = re.I | re.S) for found in match_logo.findall(html): print(found)
which returns
<img src="logo.png" alt="logo" width="100%" />
Better yet would be
from bs4 import BeautifulSoup pg = BeautifulSoup(html) print pg.find("img", {"alt":"logo"})