本文實例講述了python按照多個字符對字符串進行分割的方法。分享給大家供大家參考。具體分析如下:
這段python代碼通過這規則表達式對字符串進行分割,使用\w作為分割符,只要不是字母和數字的就會被分割開來。
- import re
- DATA = "Hey, you - what are you doing here! welcome to jb51?"
- print re.findall(r"[\w']+", DATA)
輸出結果如下
- ['Hey', 'you', 'what', 'are', 'you', 'doing', 'here', 'welcome', 'to', 'jb51'
- ]
希望本文所述對大家的Python程序設計有所幫助。