Python 使用正則表達式 將一段英文文本切割成 單詞列表


Python 使用正則表達式 將一段英文文本切割成 單詞列表,使用的語法是:

re.split(r"\b[\.,\s\n\r\n]+?\b",str)

代碼如下:

import re str=''I still have it on my note 3 and holding pretty good, I have also dropped my phone about 3 times and the case has done it's job, so I am very happy with the case, 
plus it feels very nice on the hand, and I like that the camera don't touch the outside anymore. 
happy customer here..''

if __name__ == '__main__': word_list=re.split(r"\b[\.,\s\n\r\n]+?\b",str) for word in word_list: print word

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM