例如 : 我想要把 a.txt 的内容变为**_b.txt_**
** a.txt 文件的内容**
省略几万字。。。。
2236.第的按时大大
2237.第奥术大师多撒多
省略几万字。。。。
b.txt
省略几万字。。。。
第的按时大大
第奥术大师多撒多
省略几万字。。。。
demo.py的代码应该怎么改?
demo.py
import re
with open('a.txt','+',encoding='utf-8') as f:
cont = f.read()
pirnt('原内容:\n',cont)
text = re.sub(r'^\d{4}\.?$','',cont) #表达式怎么写
print('改后:\n',text)
已经解决了:
更改过后的代码为:
import re
with open('a.txt','r',encoding='utf-8') as f:
cont = f.read()
text = re.sub(r'\d{4}\.','',cont)
with open('b.txt','w+',encoding='utf-8') as d:
d.write(text)