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

首頁 > 編程 > Python > 正文

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

2020-02-16 10:25:17
字體:
來源:轉載
供稿:網友

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

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

例子如下:

#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)

結果輸出如下:

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

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 商都县| 沂水县| 泸西县| 岳普湖县| 治县。| 靖江市| 福海县| 绩溪县| 玛纳斯县| 红河县| 霍邱县| 黔西县| 日照市| 威海市| 丰顺县| 张家港市| 桦甸市| 开封市| 中宁县| 囊谦县| 古交市| 宁安市| 扶余县| 西乌珠穆沁旗| 彝良县| 临湘市| 迭部县| 方正县| 新龙县| 郸城县| 确山县| 宁南县| 孝昌县| 满洲里市| 利辛县| 本溪市| 台北县| 凭祥市| 乌拉特中旗| 辉县市| 高台县|