Skip to main content
 首页 » 编程设计

python之正则表达式包括标志 ignorecase 和点匹配所有

2025年05月04日22mate10pro

我正在尝试将正则表达式定义为 IGNORECASE 并且点将匹配所有。
以下代码:

str = "Test " 
a = re.findall(r"(\w+)", str, re.IGNORECASE, re.S) 

得到错误

TypeError: findall() takes at most 3 positional arguments (4 given) 

请您参考如下方法:

Multiple flags can be specified by bitwise OR-ing them; re.I | re.M sets both the I and M flags, for example.

so, bitwise-or the flags:

str = "Test " 
a = re.findall(r"(\d+)", str, re.IGNORECASE|re.S)