A pair of solutions: >>> s = "central_african_republic_province.txt" >>> s.rsplit("_", 1)[-1].split(".")[0] 'province' >>> import re >>> p = re.compile(r"_ ([^_]+) \.", re.VERBOSE) >>> s = """\ ... wisconsin_state.txt ... french_guiana_district.txt ... central_african_republic_province.txt""" >>> p.findall(s) ['state', 'district', 'province']
Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list