我有一个像这个注释间隙代表新行的文件。
Hello World )
;
Hello World ) ;
Hello World )
;
我写了一个小python脚本来将分号移动到上一行的末尾
with open(path) as f:
prev_line =''
for current_line in f:
matched = re.match('[^(.+)];',current_line,re.MULTILINE)
if matched is not None:
current_line = re.sub('[^(.+)];','',current_line,re.MULTILINE)
prev_line = re.sub(r'^(.+)$',r'\1 ;',prev_line,re.MULTILINE)
print prev_line.strip()
prev_line = current_line.strip()
除了缺少分号的最后一行之外,我得到了预期的输出
Hello World ) ;
Hello World ) ;
Hello World ) **semicolon is missing here**