import re
regex = re.compile(r"^(?:[a-z]|\d+)(?:\.\d+)*\.?\s*(?:\([A-Z]\.\d+(?:\.[A-Z]\.\d+)*\)\s*)?", flags=re.MULTILINE)
test_str = ("c.2 Employed population below international poverty line, by sex and age (%) Age: 15+\n"
"b.1 Employed population below international poverty line, by sex and age (%) Age: 15+\n"
"a.1 Employed population below international poverty line, by sex and age (%) Age: 15+\n"
"1. Employed population below international poverty line, by sex and age (%) Age: 15+\n"
"1.2 Employed population below international poverty line, by sex and age (%) Age: 15+ \n"
"1.1.1 Employed population below international poverty line, by sex and age (%) Age: 15+ \n"
"5.6.2 (S.1.C.1) Employed population below international poverty line, by sex and age (%) Age: 15+\n"
"5.6.2 (S.3) Employed population below international poverty line, by sex and age (%) Age: 15+\n"
"5.6.2 (S.4.C.13) Employed population below international poverty line, by sex and age (%) Age: 15+")
subst = ""
result = regex.sub(subst, test_str)
if result:
print(result)
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html