正则sub的使用

import re

# unicode 编码匹配范围[u4e00-u9fa5]
pattern = re.compile('(\w+) (\w+)')

s = 'hello 123,hello 456'

s_list = pattern.findall(s)
print(s_list)

s_list = pattern.sub('hello world',s)
print(s_list)

 

posted @ 2018-03-10 21:42  Bob__Zhang  阅读(150)  评论(0编辑  收藏  举报