import re
result_list = re.findall(r"\d+", "我的手机号是13812345678,我的QQ号是456789123")
print(result_list, type(result_list))
print("==============")
result_iter = re.finditer(r"\d+", "我的手机号是13812345678,我的QQ号是456789123")
for match in result_iter:
print(match, type(match))
print(match.group())
print("==============")
result_match = re.search(r"\d+", "我的手机号是13812345678,我的QQ号是456789123")
print(result_match.group(), type(result_match))
print("==============")
result_match = re.match(r"\d+", "我的手机号是13812345678,我的QQ号是456789123")
try:
print(result_match.group(), type(result_match))
except Exception:
print("NoneType类型中没有group()方法")
print("================")
x = 'ascgfgadabcabfa123adc132'
r = re.sub(r'a\wc', 'xxxxx', x, count=1)
print(r, type(r))
print(x)
print("=========")
r = re.subn(r'a\wc', 'xxxxx', 'ascgfgadabcabfa123adc132')
print(r, type(r))
print("===============")
r = re.split(r'a\wc', 'ascgfgadabcabfa123adc132')
print(r, type(r))
print("==========")
obj = re.compile(r"\d+")
result_iter = obj.finditer("我的手机号是13812345678,我的QQ号是456789123")
for match in result_iter:
print(match.group())
print("================")
s = """
<div class='jay'><span id='1'>抽烟</span></div>
<div class='jj'><span id='2'>喝酒</span></div>
<div class='jolin'><span id='3'>烫头</span></div>
<div class='sylar'><span id='4'>阿巴阿巴</span></div>
<div class='tory'><span id='5'>???</span></div>
"""
obj = re.compile(r"<div class='.*?'><span id='(?P<id>.*?)'>(?P<content>.*?)</span></div>", re.S)
result_iter = obj.finditer(s)
for match in result_iter:
print(match.group(2))
print(match.group("id"))
print(match.groupdict())
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步