>>> text= """ this is an example Item 2 text text <B>Item 2. example"""
>>> a=re.search ('(?<=<B>)Item 2\.',text)
>>> b = a.span()
>>> print (b)
(45, 57)
>>>
In [76]: import re
In [77]: text = """ this is an example Item 2 text text <B>Item 2. example"""
In [78]: a = re.search ('(?<=<B>)Item 2\.',text)
In [79]: start, end = a.span()
In [80]: text[:start]
Out[80]: ' this is an example Item 2 text text <B>'
match对象a也知道text的值;可以通过其string属性访问它:
In [91]: a.string[:start]
Out[91]: ' this is an example Item 2 text text <B>'
使用
text[:start]
:match对象
a
也知道text
的值;可以通过其string
属性访问它:相关问题 更多 >
编程相关推荐