久久久精品2019免费观看_亚洲国产精品成人久久久_69国产成人综合久久精品91_国产精品久久精品视

python提取中文的正則表達式

當(dāng)我們用python爬取一些網(wǎng)站的時候,會發(fā)現(xiàn)有的是中英又語的,但是我們只需要中文,這時候怎么寫正則表達式呢,首先給出答案: [\u3002\uff1b\uff0c\uff1a\u201c\u201d\uff08\uff09\u3001\uff1f\u300a\u300b]
朋友們可以先運行一下下面的例子加深印象。
s = ”’I am ten years old now, I am studying at a primary school, and I am in grade four. There are many subjects for me to learn, among them, I like Chinese the most. Chinese is our country’s language, it has more than five thousand years of history. I am so interested in Chinese culture, and learning Chinese well can help me understand Chinese culture better.
我現(xiàn)在十歲了,我在一所小學(xué)上學(xué),我現(xiàn)在讀四年級。我要學(xué)很多的科目,在這些科目當(dāng)中,我最喜歡語文。漢語是我們國家的語言,有超過五千年的歷史。我對中國的歷史很感興趣,學(xué)好語文能讓我更好的了解中國歷史。”’
t = re.findall(‘[\u3002\uff1b\uff0c\uff1a\u201c\u201d\uff08\uff09\u3001\uff1f\u300a\u300b\u4e00-\u9fa5]’,s)
print(”.join(t))
運行結(jié)果如下:

未經(jīng)允許不得轉(zhuǎn)載:445IT之家 » python提取中文的正則表達式

贊 (2) 打賞

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

微信掃一掃打賞