简体   繁体   中英

python replace special characters except dashes and periods

I would like to replace every special character but leave dashes and periods. I have re.sub('[^a-zA-Z]+', ' ', corpus , which replaces everything. How do I modify it to leave periods and dashes?

在否定的字符类中添加句点和破折号。

re.sub('[^a-zA-Z.-]+', ' ', corpus)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM