国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

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

2020-01-04 16:36:41
字體:
供稿:網(wǎng)友

詳解python/272134.html">python里使用正則表達(dá)式的全匹配功能

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

例子如下:

#python 3.6#蔡軍生 #http://blog.csdn.net/caimouse/article/details/51749579#import retext = '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  : isSearch   : <_sre.SRE_Match object; span=(2, 4), match='is'>Full match : NoneText    : isFull match : <_sre.SRE_Match object; span=(0, 2), match='is'>Text    : issFull match : None

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


注:相關(guān)教程知識閱讀請移步到python教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 曲水县| 博客| 辽阳市| 高青县| 鸡西市| 汨罗市| 抚顺县| 澄江县| 葫芦岛市| 桂平市| 青海省| 桂林市| 阿克苏市| 修水县| 宜丰县| 称多县| 崇仁县| 旬阳县| 鹤山市| 云安县| 南皮县| 库伦旗| 金山区| 保山市| 昌黎县| 株洲县| 宜宾市| 湟源县| 定结县| 中西区| 嘉兴市| 太仓市| 曲靖市| 云龙县| 中山市| 二连浩特市| 舒城县| 兴化市| 武汉市| 株洲市| 威海市|