Есть несколько способов сделать это с помощью регулярных выражений, но обычно это будет сложнее, чем, вероятно, не лучшим способом. Например, с выражением, похожим на:
^(?:\([^)]+\))\s*(.*)
Тест с re.findall
import re
regex = r"^(?:\([^)]+\))\s*(.*)"
test_str = ("(a) This is my first paragraph, which is some junk text\n\n"
"(b) This is another paragraph, but it incidentally has some reference to another paragraph which refers to clause 945(d)\n\n"
"(c) This again is is some third paragraph")
print(re.findall(regex, test_str, re.MULTILINE))
выход
['This is my first paragraph, which is some junk text', 'This is another paragraph, but it incidentally has some reference to another paragraph which refers to clause 945(d)', 'This again is is some third paragraph']
Тест с re.sub
import re
regex = r"^(?:\([^)]+\))\s*(.*)"
test_str = ("(a) This is my first paragraph, which is some junk text\n\n"
"(b) This is another paragraph, but it incidentally has some reference to another paragraph which refers to clause 945(d)\n\n"
"(c) This again is is some third paragraph")
subst = "\\1"
print(re.sub(regex, subst, test_str, 0, re.MULTILINE))
Тест с re.finditer
import re
regex = r"^(?:\([^)]+\))\s*(.*)"
test_str = ("(a) This is my first paragraph, which is some junk text\n\n"
"(b) This is another paragraph, but it incidentally has some reference to another paragraph which refers to clause 945(d)\n\n"
"(c) This again is is some third paragraph")
matches = re.finditer(regex, test_str, re.MULTILINE)
for matchNum, match in enumerate(matches, start=1):
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
Выражение объяснено на верхней правой панели этой демонстрации , если вы хотите изучить / упростить / изменить его, а в этой ссылке вы можете посмотреть, как оно будет если хотите, сравнивайте с некоторыми примерами ввода шаг за шагом.
RegEx Circuit
jex.im визуализирует регулярные выражения: