例如re.sub(r’\W+’ ,’ ‘ ,text):There’s a novel name as 「Harry Potter」, best-seller of amazon store! 可以轉換成 There s a novel as Harry Potter best seller of amazon store!
[python]
import re
text = """
There's a novel name as 「Harry Potter」, best-seller of amazon store!
"""
# 只保留英文字母跟數字還有_,大寫W就是比對到其他的項目,並轉換成空格
replaceString = re.sub(r'\W+' ,' ' ,text)
print(replaceString)
# There s a novel as Harry Potter best seller of amazon store
# 只保留英文字母跟數字還有_,在轉換成小寫
replaceStringLower = re.sub(r'\W+' ,' ' ,text).lower()
print(replaceString)
# there s a novel as harry potter best seller of amazon store
[/python]