正则表达式
发布时间:2020-12-13 22:57:48 所属栏目:百科 来源:网络整理
导读:1 正则表达式的匹配 import reprint("example1")s= re.match("abc","abc") #普通字符与普通字符匹配if s==None: print ("No match")else: print("Yes match")print("example2")s= re.match("a.c","axc") #点与任意字符匹配if s==None: print ("No match")els
1 正则表达式的匹配 import re print("example1") s= re.match("abc","abc") #普通字符与普通字符匹配 if s==None: print ("No match") else: print("Yes match") print("example2") s= re.match("a.c","axc") #点与任意字符匹配 if s==None: print ("No match") else: print("Yes match") print("example3") s= re.match("a.c","a.c") #反斜杠为转义字符 if s==None: print ("No match") else: print("Yes match") print("example4") #[a-z]表示a-z中的任意一个字符 s= re.match("a[a-z]c","aAc") if s==None: print ("No match") else: print("Yes match") print("example5") #前面加^表示不存在 s= re.match("a[^a-z]c","aAc") if s==None: print ("No match") else: print("Yes match") print("example6") s= re.match("ac{2}","accdd") #{2}表示要求前面的字符出现2次 if s==None: print ("No match") else: print("Yes match") print("example7") #Z表示要求在行尾匹配 s= re.match("acZ","accddax") if s==None: print ("No match") else: print("Yes match") (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |