当前位置:  首页>> 技术小册>> Python合辑4-130个字符串操作示例

将字符串拆分为具有多个单词边界分隔符的单词

  1. import re
  2. thestring = "a,b,c d!e.f\ncanada\tjapan&germany"
  3. listitems = re.findall('\w+', thestring)
  4. for item in listitems:
  5. print(item)

Output:

  1. a
  2. b
  3. c
  4. d
  5. e
  6. f
  7. canada
  8. japan
  9. germany