python正则表达式将字符串切割成单词列表

版权声明:本文为博主原创文章,欢迎转载,请注明出处。 https://blog.csdn.net/plgy_Y/article/details/75377455
# -*-coding:utf-8-*-
import re
str='''I like to read novel books. 
When I start    to go to primary school,
 my parents have bought me a lot of novel books,
  because they want me to fall in love with reading. 
  Indeed, thanks to these books, I feel very excited about studying
  the knowledge. The novel books open my vision and 
  I am good at writing. I want to write a book and read them
   to my families and friends.'''
if __name__ == '__main__':
    word_list=re.split(r"\b[\.,\s\n\r\n]+?\b",str)
    for word in word_list:
        print word

猜你喜欢

转载自blog.csdn.net/plgy_Y/article/details/75377455