Pycharm误删文件还能找回吗
import rea = '1234'
r = re.findall('\d{2}', a)
print(r)结果为‘12’、‘34’
我想要的结果是 12’、‘23’,‘34’
请问各位大神怎么修改结果为‘12’、‘34’
我想要的结果是 12’、‘23’,‘34’
请问各位大神怎么修改
正则应该无法实现吧 import re
def sub(string, p, c):
new = []
for s in string:
new.append(s)
new = c
return ''.join(new)
if __name__ == '__main__':
a = '1234'
results = []
while True:
r = re.search('\d{2}', a)
if r:
result = r.group()
results.append(result)
a = sub(a, r.span(), '*')
else:
break
print(results) 一行正则应该不行,先用正则把str的数字提取出来,然后遍历成12’、‘23’,‘34’ import re
a = '1234'
pat = r'(\d(?=(\d)))'
r = re.findall(pat, a)
t = [''.join(i) for i in r]
print(t)
# ['12', '23', '34']
页:
[1]