|
|
发表于 2017-4-19 12:24:38
|
显示全部楼层
- >>> import re
- >>> re.search(r'FishC','I love FishC.com!')
- <_sre.SRE_Match object; span=(7, 12), match='FishC'>
- >>> m=re.search(r'FishC','I love FishC.com!')
- >>> dir(m)
- ['__class__', '__copy__', '__deepcopy__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'end', 'endpos', 'expand', 'group', 'groupdict', 'groups', 'lastgroup', 'lastindex', 'pos', 're', 'regs', 'span', 'start', 'string']
- >>> print(m.span())
- (7, 12)
- >>> 'I love FishC.com!'[slice(*m.span())]
- 'FishC'
- >>>
复制代码 |
|