Python Regex re.sub not working in For loop -
i unable replace particular occurrence of pattern edited text. have used for...loop come how specific occurrence of pattern unable use re.sub statement.
this python 2 code:
def split(content): count = 0 s = "" 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 on line:
content = re.sub(i,s,content)
since variable "i" apparently not regex.
the error:
typeerror: first argument must string or compiled pattern
how can fix problem??
thanks.
i'm not sure want, error telling right thing: i
isn't regex pattern. re.finditer
returns iterator of matchobject
s, strings in context. re.sub
expects regular expression pattern first argument.
depending on you're trying achieve code, either need use different function re.sub
, or need supply actual regex. if can give more details goals (maybe expected output based on sample input, @200_success suggests), help.
Comments
Post a Comment