If you are a newbie, you should learn Python 3.x instead of Python 2.x.
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import re thefile = open("ss100.txt", "r") for line in thefile: line = line.strip() # strip end-on-line if re.match(r"h...g..", line) and len(line)==7: print(line)