0
点赞
收藏
分享

微信扫一扫

Python匹配对象与索引使用

高子歌 2022-08-02 阅读 162
编程语言

>>> s='''Lisf can be dreams,
...Lisfe can be great thoughts;
...Life can mean a person
...Sitting in a count.''' r=re.compile("\\b(?P<first>\w+)a(\w+)\\b")

>>> m=r.search(s)
>>> m

<_sre.SRE_Match object; span=(5, 8), match='can'>

>>> m.start()

5

>>> m=r.search(s,9)

>>> m.start()

12

>>> m.start(1)

12

>>> m.start(2)

16

>>> m.end(1)

15

>>> m.end()

18

>>> m.span()

(12, 18)

>>> s[12:18]

'dreams'

>>> m.span(2)

(16, 18)

举报

相关推荐

0 条评论