-
学习正则表达式的基本用法。
-
使用Python进行文本清洗。
import re
def clean_text(text):
text = re.sub(r'\s+', ' ', text) # 去除多余空格
text = re.sub(r'[^\w\s]', '', text) # 去除标点符号
return text
sample_text = "This is a sample text! It has punctuation, and extra spaces."
print(clean_text(sample_text))
浙公网安备 33010602011771号