#正则 之 search方法 import re # 1、match和search的区别 pattern=re.compile(r'\d+') s=pattern.search('one1two2') print(s) print(s.group()) #2.分组 pattern = re.compile(r'(\d+) (\d+)') s = pattern.search("hello 123456 789") print(s.group()) print(s.groups())
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 /Users/apple/PycharmProjects/stage4/spider/2018——0307/03re_search.py
<_sre.SRE_Match object; span=(3, 4), match='1'>
1
123456 789
('123456', '789')
Process finished with exit code 0