标签:pattern else 范围 span int 失败 字符 match 字符串
1 import re 2 s = ‘hello python‘ 3 pattern = ‘hello‘ 4 v = re.match(pattern,s) 5 print(v) 6 #print(dir(v)) 7 print(v.group()) # 返回当前匹配的字符串 8 print(v.span()) # 匹配字符串的范围 9 print(‘--------flags参数的使用-------‘) 10 s = ‘hello python‘ 11 pattern = ‘Hello‘ 12 w = re.match(pattern,s,flags=re.I) # 忽略大小写 13 if w is not None: 14 print(‘匹配的结果是:‘,w.group()) 15 else: 16 print(‘匹配失败‘)
1 <re.Match object; span=(0, 5), match=‘hello‘> 2 hello 3 (0, 5) 4 --------flags参数的使用------- 5 匹配的结果是: hello
标签:pattern else 范围 span int 失败 字符 match 字符串
原文地址:https://www.cnblogs.com/monsterhy123/p/12904661.html