【发布时间】:2021-11-04 02:04:26
【问题描述】:
我有一个字符串:
5956 Executive Dr #101, Fitchburg, WI 53719
我希望它是:
5956 Executive Dr, Fitchburg, WI 53719
我试过了:
string2 = re.sub("(\\.*)\\s+#.*", "\\1", string1)
但这只是让我明白:
5956 Executive Dr
如何在 Python 中做到这一点?我发现 re 表达式很混乱。理想情况下,我想对 Apt、Unit 等做同样的事情 - 用“”替换任何实例,如“Apt 3”、“Unit 3”、“Suite 4”。
【问题讨论】:
标签: python substring python-re