Jul-07-2025, 12:12 AM
For regex advice try https://www.rexegg.com
Here a simpler, easier to understand regex to do what you want:
Here a simpler, easier to understand regex to do what you want:
import re
from pathlib import Path
afile = Path(r'/home/peterr/temp/OFINI field definitions1.txt')
newfile = Path(r'/home/peterr/temp/OFINI field definitions1.txt.altered')
# easier to understand regex
# get everything except the first and last "
# I don't think you need worry about multilinelines in your files
h = re.compile(r'\A"(.*)"\Z')
# leave the original file untouched
with open(afile) as infile, open(newfile, 'w') as outfile:
lines = infile.readlines()
for line in lines:
# get rid of the newline
line = line.strip()
res = h.search(line)
if res:
newline = res.group(1) + '\n'
outfile.write(newline)Little bit of output:Output:; .OFINI ;field definitions
; .OFDEF Fd.Nxt , 2. ;00 offset from PC to next field
; .OFDEF Fd.Max , 1. ;01 maximum input characters
; .OFDEF Fd.Min , 1. ;02 minimum input characters
