import repattern = re.compile(r'\d+')print(re.split(pattern,'one1two2three3four4'))import repattern = re.compile(r'\d+')print(re.findall(pattern,'one1two2three3four4'))为什么第一个结果是英文第二个是数字
1 回答
守着星空守着你
TA贡献1799条经验 获得超8个赞
你的Python程序输出结果是对的.
re.split是以re.compile中的正则表达式对字符串进行切分.
re.findall是以re.compile中的正则表达式对字符串进行匹配.
就拿你的例子来说吧, re.split是以数字为边界对字符串'one1two2three3four4'进行切分,得到['one','two','three','four','']五个字符串 re.findall是匹配字符串'one1two2three3four4'中的所有数字,得到['1','2','3','4']四个数字
添加回答
举报
0/150
提交
取消
