欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

詳解python里使用正則表達(dá)式的全匹配功能

 更新時(shí)間:2017年10月19日 08:40:53   作者:caimouse  
這篇文章主要介紹了詳解python里使用正則表達(dá)式的全匹配功能的相關(guān)資料,希望通過本文能幫助到大家,需要的朋友可以參考下

詳解python里使用正則表達(dá)式的全匹配功能

python中很多匹配,比如搜索任意位置的search()函數(shù),搜索邊界的match()函數(shù),現(xiàn)在還需要學(xué)習(xí)一個(gè)全匹配函數(shù),就是搜索的字符與內(nèi)容全部匹配,它就是fullmatch()函數(shù)。

例子如下:

#python 3.6
#蔡軍生 
#http://blog.csdn.net/caimouse/article/details/51749579
#
import re


text = 'This is some text -- with punctuation.'
pattern = 'is'


print('Text    :', text)
print('Pattern  :', pattern)


m = re.search(pattern, text)
print('Search   :', m)
s = re.fullmatch(pattern, text)
print('Full match :', s)




text = 'is'
print('Text    :', text)
s = re.fullmatch(pattern, text)
print('Full match :', s)


text = 'iss'
print('Text    :', text)
s = re.fullmatch(pattern, text)
print('Full match :', s)

結(jié)果輸出如下:

Text    : This is some text -- with punctuation.
Pattern  : is
Search   : <_sre.SRE_Match object; span=(2, 4), match='is'>
Full match : None
Text    : is
Full match : <_sre.SRE_Match object; span=(0, 2), match='is'>
Text    : iss
Full match : None

如有疑問請(qǐng)留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

相關(guān)文章

最新評(píng)論