【发布时间】:2020-08-27 17:11:16
【问题描述】:
以下代码:
import re
print(re.sub('[^a-zA-Z0-9]', '', ',Inc.', re.IGNORECASE).lower())
print(re.sub('[^a-zA-Z0-9]', '', ', Inc.', re.IGNORECASE).lower())
产生:
inc
inc.
https://repl.it/repls/RightThankfulMaintenance
为什么?
【问题讨论】:
-
re.sub的第四个参数是计数,而不是标志。应该是re.sub('[^a-zA-Z0-9]', '', ',Inc.',0, re.IGNORECASE) -
知道我忘记了一些愚蠢的事情。谢谢!
标签: python python-3.x regex re