import re #替换 pattern = re.compile(r'(\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)
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 /Users/apple/PycharmProjects/stage4/spider/2018——0307/re_sub.py
[('hello', '123'), ('hello', '456')]
hello world,hello world
Process finished with exit code 0