[英]Python Regex— TypeError: an integer is required
I am receiving an error on the .match regex module function of TypeError: An integer is required. 我收到TypeError的.match正则表达式模块函数的错误:需要一个整数。
Here is my code: 这是我的代码:
hAndL = hAndL.replace('epsilo\ell','epsilon')
pattern = re.compile("\frac{.*?}{ \frac{.*?}{.*?}}")
matching = pattern.match(pattern,hAndL)
hAndL is a string and pattern is a..pattern. hAndL是一个字符串,模式是一个..模式。
I'm not sure why this error is happening, any help is appreciated! 我不确定为什么会发生这种错误,感谢任何帮助!
When you re.compile
a regular expression, you don't need to pass the regex object back to itself . 重新re.compile
正则表达式时, 不需要将正则表达式对象传递回自身 。 Per the documentation: 根据文件:
The sequence 序列
prog = re.compile(pattern) result = prog.match(string)
is equivalent to 相当于
result = re.match(pattern, string)
The pattern
is already provided, so in your example: 该pattern
已经提供,因此在您的示例中:
pattern.match(pattern, hAndL)
is equivalent to: 相当于:
re.match(pattern, pattern, hAndL)
# ^ passing pattern twice
# ^ hAndL becomes third parameter
where the third parameter to re.match
is flags
, which must be an integer. 其中re.match
的第三个参数是flags
,它必须是一个整数。 Instead, you should do: 相反,你应该这样做:
pattern.match(hAndL)
hAndL = hAndL.replace('epsilo\ell','epsilon')
pattern = re.compile("\frac{.*?}{ \frac{.*?}{.*?}}")
matching = pattern.match(hAndL)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.