import re
regex = re.compile(r"\]\s*(?:\d+|[a-zA-Z]+)\.\s*", flags=re.MULTILINE)
test_str = ("[ 1.1 ] 1. A method of providing a master\n"
"[ 12.1 ] 12. An apparatus for providing\n"
"[ 39.3 ] b. one or more control point applications\n"
"[ 39.8 ] iv. a server application programming interface\n"
"[ 30.2 ] a. a client application programming\n"
"[ 1.2 ] an RFID device provided")
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