我正在尝试查找文件中以开头和结尾的行。我正在使用正则表达式,但无法获得结果。
我尝试过使用各种选项的正则表达式,例如\s、\S、\W和\w。
import re
infile=open("C:\\Users\\Downloads\\Files\\processed.csv","r")
myregex = re.compile(r'(^\[)(\]$)')
list=[]
for groups in myregex.findall(infile.read()):
item=''.join(groups)
cleanitem=item.replace('\n','')
list.append(cleanitem)
print (list)
infile.close()
它应该打印所有以开头和结尾的行。
我该如何解决这个问题?
https://stackoverflow.com/questions/56386287
复制相似问题