作者:鉴佳熙萍 | 来源:互联网 | 2023-09-23 17:03
Iwanttoreplaceallnon-alphabeticcharacterswithspaces,excludingyearsbetween1950and2029.
I want to replace all non-alphabetic characters with spaces, excluding years between 1950 and 2029. E.g.:
我想用空格替换所有非字母字符,不包括1950年至2029年之间的年份。例如:
ab-c 0123 4r. a2017 2010
-> ab c r a 2010
ab-c 0123 4 r。a2017 2010 -> ab c r a 2010。
My attempt so far, trying to blacklist the dates via a negative look-ahead:
到目前为止,我的尝试是通过消极的展望将日期列入黑名单:
re.sub('(?!\b19[5-9][0-9]\b|\b20[0-2][0-9]\b)([^A-Za-z]+)', ' ', string)
Since this doesn't work, any help is greatly appreciated!
因为这不起作用,所以非常感谢您的帮助!
3 个解决方案