>>> import re >>> a = re.search('/thumbnail/(\w+)\.html', '/thumbnail/abcdefg.html') >>> a.group() '/thumbnail/abcdefg.html' >>> a.group(1) 'abcdefg' >>>