标签:编写 字节 编译 指定 引擎 次数 gone rup 字节码
import re s = re.findall(‘\w‘,‘123euiooj--=,..‘) print(s) 运行结果: [‘1‘, ‘2‘, ‘3‘, ‘e‘, ‘u‘, ‘i‘, ‘o‘, ‘o‘, ‘j‘] s = re.findall(‘\W‘,‘123euiooj--=,..‘) print(s) 运行结果: [‘-‘, ‘-‘, ‘=‘, ‘,‘, ‘.‘, ‘.‘]
s = re.findall(‘\s‘,‘nihao, my world ‘) print(s) 运行结果: [‘ ‘, ‘ ‘, ‘ ‘] s = re.findall(‘\S‘,‘nihao, my world ‘) print(s) 运行结果: [‘n‘, ‘i‘, ‘h‘, ‘a‘, ‘o‘, ‘,‘, ‘m‘, ‘y‘, ‘w‘, ‘o‘, ‘r‘, ‘l‘, ‘d‘]
s = re.findall(‘\d‘,‘nihao123456‘) print(s) 运行结果: [‘1‘, ‘2‘, ‘3‘, ‘4‘, ‘5‘, ‘6‘] s = re.findall(‘\D‘,‘nihao123456‘) print(s) 运行结果: [‘n‘, ‘i‘, ‘h‘, ‘a‘, ‘o‘]
s = re.findall(‘\An‘,‘nnnihao123456‘) print(s) 运行结果: [‘n‘]
s = re.findall(‘n\Z‘,‘ihao123456n‘) print(s) 打印结果: [‘n‘]
s = re.findall(‘\n‘,‘ihao123456n\n‘) print(s) 打印结果: [‘\n‘]
s = re.findall(‘\n\t‘,‘ihao123456n\n\t‘) print(s) 打印结果: [‘\n\t‘]
s = re.findall(‘^a‘,‘aaaihao123456n‘) print(s)--跟\A功能类似 打印结果:[‘a‘]
s = re.findall(‘a$‘,‘ihao123456naaaa‘) print(s)--跟\Z功能类似 打印结果: [‘a‘]
s = re.findall(‘.‘,‘ihao123456naa\n‘) print(s) 打印结果: [‘i‘, ‘h‘, ‘a‘, ‘o‘, ‘1‘, ‘2‘, ‘3‘, ‘4‘, ‘5‘, ‘6‘, ‘n‘, ‘a‘, ‘a‘]
print(re.findall(‘a.b‘, ‘ab aab a*b a2b a牛b a\nb‘)) 打印结果: [‘aab‘, ‘a*b‘, ‘a2b‘, ‘a牛b‘]
print(re.findall(‘a.b‘,‘ab aab a*b a2b a牛b a\nb‘,re.DOTALL)) 打印结果: [‘aab‘, ‘a*b‘, ‘a2b‘, ‘a牛b‘, ‘a\nb‘]
print(re.findall(‘a[abc]b‘, ‘aab abb acb adb afb a_b‘)) 打印结果: [‘aab‘, ‘abb‘, ‘acb‘]
print(re.findall(‘a[0-9]b‘, ‘a1b a3b aeb a*b arb a_b‘)) 打印结果: [‘a1b‘, ‘a3b‘]
print(re.findall(‘a[-*+]b‘, ‘a-b a*b a+b a/b a6b‘)) 打印结果: [‘a-b‘, ‘a*b‘, ‘a+b‘]
print(re.findall(‘a[^a-z]b‘, ‘acb adb a3b a*b‘)) 打印结果: [‘a3b‘, ‘a*b‘]
print(re.findall(‘a*b‘, ‘ab aab aaab abbb‘)) 打印结果: [‘ab‘, ‘aab‘, ‘aaab‘, ‘ab‘, ‘b‘, ‘b‘]
print(re.findall(‘ab*‘, ‘ab aab aaab abbbbb‘)) 打印结果: [‘ab‘, ‘a‘, ‘ab‘, ‘a‘, ‘a‘, ‘ab‘, ‘abbbbb‘]
print(re.findall(‘a+b‘, ‘ab aab aaab abbb‘)) 打印结果: [‘ab‘, ‘aab‘, ‘aaab‘, ‘ab‘]
print(re.findall(‘a?b‘, ‘ab aab abb aaaab a牛b aba**b‘)) 打印结果: [‘ab‘, ‘ab‘, ‘ab‘, ‘b‘, ‘ab‘, ‘b‘, ‘ab‘, ‘b‘]
print(re.findall(‘a{2}b‘, ‘ab aab aaab aaaaabb‘)) 打印结果: [‘aab‘, ‘aab‘, ‘aab‘]
print(re.findall(‘a{2,4}b‘, ‘ab aab aaab aaaaabb‘)) 打印结果: [‘aab‘, ‘aaab‘, ‘aaaab‘]
print(re.findall(‘a|b‘,‘alex_sb ale123_sb wusir12_sb wusir_sb ritian_sb‘)) 打印结果: [‘a‘, ‘b‘, ‘a‘, ‘b‘, ‘b‘, ‘b‘, ‘a‘, ‘b‘]
print(re.findall(‘alex|太白|wusir‘, ‘alex太白wusiraleeeex太太白odlb‘)) 打印结果: [‘alex‘, ‘太白‘, ‘wusir‘, ‘太白‘]
print(re.findall(‘([a-z]+)_sb‘,‘alex_sb ale123_sb wusir12_sb wusir_sb ritian_sb‘)) 打印结果: [‘alex‘, ‘wusir‘, ‘ritian‘]
print(re.findall(‘(.*?)_sb‘, ‘alex_sb wusir_sb 日天_sb‘)) 打印结果 [‘alex‘, ‘ wusir‘, ‘ 日天‘]
print(re.findall(‘compan(y|ies)‘,‘Too many companies have gone bankrupt, and the next one is my company‘)) 打印结果: [‘ies‘, ‘y‘] 分组() 中加入?: 表示将整体匹配出来而不只是()里面的内容 print(re.findall(‘compan(?:y|ies)‘,‘Too many companies have gone bankrupt, and the next one is my company‘)) 打印结果: [‘companies‘, ‘company‘]
print(re.findall(‘a.*b‘, ‘ab aab a*()b‘)) 打印结果: [‘ab aab a*()b‘]
print(re.findall(‘a.*?b‘, ‘ab a1b a*()b, aaaaaab‘)) 打印结果: [‘ab‘, ‘a1b‘, ‘a*()b‘, ‘aaaaaab‘]
import re s = re.search(‘alex‘,‘alex sb sb alex 日天‘) ##这是个对象 print(s.group()) 打印结果: alex
s = re.match(‘alex‘,‘alex sb alex sb sb alex 日天‘) print(s.group()) 打印结果: alex
print(re.split(‘[ ::,;;,]‘,‘alex wusir,日天,太白;女神;肖锋:吴超‘)) 打印结果: [‘alex‘, ‘wusir‘, ‘日天‘, ‘太白‘, ‘女神‘, ‘肖锋‘, ‘吴超‘]
s = re.sub(‘小红‘,‘小黄‘,‘小红和小兰,明天要跟小明一起去郊游,但是小红不想去‘) print(s) 打印结果: 小黄和小兰,明天要跟小明一起去郊游,但是小黄不想去
s = re.sub(‘小红‘,‘小黄‘,‘小红和小兰,明天要跟小明一起去郊游,但是小红不想去‘,1) print(s) 打印结果: 小黄和小兰,明天要跟小明一起去郊游,但是小红不想去
obj = re.compile(‘\d{2}‘) print(obj.search(‘abc123eeee‘).group()) #12 print(obj.findall(‘abc123eeee‘)) #[‘12‘],重用了obj 打印结果: 12 [‘12‘]
ret = re.finditer(‘\d‘,‘123day788add‘) print(ret.__next__().group()) print([i.group() for i in ret]) 打印结果: 1 [‘2‘, ‘3‘, ‘7‘, ‘8‘, ‘8‘]
ret = re.search("<(?P<tag_name1>\w+)>\w+</(?P=tag_name1)>","<h1>hello</h1>") print(ret.group(‘tag_name1‘)) print(ret.group()) 打印结果: h1 <h1>hello</h1>
标签:编写 字节 编译 指定 引擎 次数 gone rup 字节码
原文地址:https://www.cnblogs.com/Ailsa-a/p/10397150.html