I know there have been several questions on this subject already, but none help me resolve my problem.
I have to replace names in a CSV document when they follow the tags {SPEAKER}
or {GROUP OF SPEAKERS}
.
Code
The erroneous part of my script is:
list_speakers = re.compile(r'^\{GROUP OF SPEAKERS\}\t(.*)|^\{SPEAKER\}\t(.*)')
usernames = set()
for f in corpus:
with open(f, "r", encoding=encoding) as fin:
line = fin.readline()
while line:
line = line.rstrip()
if not line:
line = fin.readline()
continue
if not list_speakers.match(line):
line = fin.readline()
continue
names = list_speakers.sub(r'\1', line)
names = names.split(", ")
for name in names:
usernames.add(name)
line = fin.readline()
Error
However, I receive the following error message :
File "/usr/lib/python2.7/re.py", line 291, in filter
return sre_parse.expand_template(template, match)
File "/usr/lib/python2.7/sre_parse.py", line 831, in expand_template
raise error, "unmatched group"
sre_constants.error: unmatched group
I am using Python 2.7.
How can I fix this?