I am unable to replace a particular occurrence of a certain pattern with edited text. I have used a for...loop to come up with how to get a specific occurrence of the pattern but I am unable to use that with an re.sub statement.
This is my Python 2 code:
def split(content):
count = 0
s = ""
for i in re.finditer(r'(?s)(\\thinhline\n\\\\\[-16pt]\n)([a-zA-Z\s\(\)]+)(.*?)(\n *\\\\)', content):
count= count + 1
x = len(re.findall('^\s*&', i.group(3), re.M))
if x < 6:
break
elif x >= 6:
g = normalizationConstraints(i.group(3),i.group(2)) + "\n"
s = str(g) + "\n"
content = re.sub(i,s,content)
return content
The error is on the line:
content = re.sub(i,s,content)
Since the variable "i" is apparently not regex.
The error:
TypeError: first argument must be string or compiled pattern
How can I fix this problem??
Thanks.
iis? have you tried printingi?