1
我正在讀取包含Linux樹輸出的文件的腳本,我想刪除每行開頭的樹格式。但是,我想保留字符串後的第一個字母或數字的間距。Python刪除字符,直到字母或數字
這是我到目前爲止有:
import re
with open(tree_loc) as f:
for line in f:
if 'batman' in line:
line = re.sub(r'[^\w*]', '', line)
print(line)
嘗試're.sub(r'^ \ W +','',line)' –