代码拉取完成,页面将自动刷新
import re
result = re.split('---', 'aaa---bbb---ccc')
print(result)
result = re.sub('--', '...', 'aaa--bbb--ccc')
print(result)
result = re.split('[-=]', 'aaa-bbb=ccc')
print(result)
result = re.split('(--)|(==)', 'aaa--bbb==ccc')
print(result)
result = re.split('(?:--)|(?:==)', 'aaa--bbb==ccc')
print(result)
=========================================================
import re
str1 = 'spam/ham/eggs'
result = str1.split('/')
print(result)
result = re.match('(.*)/(.*)/(.*)', str1).groups()
print(result)
str2 = '<spam>/<ham>/<eggs>'
result = re.match('<(.*)>/<(.*)>/<(.*)>', str2).groups()
print(result)
str3 = ' <spam>/<ham><eggs>'
result = re.match('\s*<(.*)>/?<(.*)>/?<(.*)>', str2).groups()
print(result)
str4 = 'Hello pattern world!'
result = str4.split()
print(result)
str5 = 'Hellopattern world !'
result = re.match('Hello\s*([a-z]*)\s+(.*?)\s*!', str5).groups()
print(result)
====================================================================
import re
str1 = '<spam>/<ham>/<eggs>'
result = str1.find('ham')
print(result)
result = re.findall('<(.*?)>', str1)
print(result)
str2 = '<spam> / <ham>/<eggs>'
result = re.findall('<(.*?)>', str2)
print(result)
str3 = '<spam>/<ham> ... <eggs>/<cheese>'
result = re.findall('<(.*?)>/?<(.*?)>', str3)
print(result)
str4 = 'todays menu: <spam>/<ham> ... <eggs><s>'
result = re.search('<(.*?)>/?<(.*?)>', str4).groups()
print(result)
========================================================
import re
str1 = '<spam> \n <ham>\n<eggs>'
result = re.findall('<(.*?)>.*<(.*?)>', str1)
print(result)
#[]
result = re.findall('(?s)<(.*?)>.*<(.*?)>', str1)
print(result)
#[('spam', 'eggs')]
result = re.findall('(?s)<(.*?)>.*?<(.*?)>', str1)
print(result)
#[('spam', 'ham')]
========================================================
import re
str1 = '...aaa/bbb/ccc]'
result = re.search('(?P<part1>\w*)/(?P<part2>\w*)', str1).groups()
print(result)
#('aaa', 'bbb')
result = re.search('(?P<part1>\w*)/(?P<part2>\w*)', str1).groupdict()
print(result)
#{'part1': 'aaa', 'part2': 'bbb'}
result = re.search('(?P<part1>\w*)/(?P<part2>\w*)', str1).group(2)
print(result)
#bbb
result = re.search('(?P<part1>\w*)/(?P<part2>\w*)', str1).group('part2')
print(result)
#bbb
str2 = '...aaa/bbb ccc/ddd]'
result = re.findall('(?P<part1>\w*)/(?P<part2>\w*)', str2)
print(result)
#[('aaa', 'bbb'), ('ccc', 'ddd')]
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。