Search & Replace regex
-
Good day,
I am trying to do a Search & Replace on text file to invert some text:
“T3A”,“LC0721”,“LC0721”,“CALGARY LCD 11”,“60”,“197”,“”,“”,“HAI025 1-AB”,“Disc menu EN”
“T3A”,“LC0724”,“LC0724”,“CALGARY LCD 11”,“218”,“22”,“”,“”,“HAI025 1-AB”,“Disc menu EN”I want the section “HAI025 1-AB” to become “1-AB HAI025”. I am using the
Regular expression selected:Find what: (\HAI…) (.*?")
Replace with : \2 \1Results:
“T3A”,“LC0721”,“LC0721”,“CALGARY LCD 11”,“60”,“197”,“”,“”,“1-AB” HAI025,“Disc menu EN”
“T3A”,“LC0724”,“LC0724”,“CALGARY LCD 11”,“218”,“22”,“”,“”,“1-AB” HAI025,“Disc menu EN”I am getting that extra quote " after the AB where I would to get just a space and the quote " at the end of that field before the comma.
How do I substract the last character from the \1 and add that extra quote at the end?
Tx for your help,
Yves
-
Why not just change it to?:
Find:
(?-is)"(HAI...) (.*?)"
Replace:"\2 \1"
Search mode: Regular expressionThat will take this data:
"T3A","LC0721","LC0721","CALGARY LCD 11","60","197","","","HAI025 1-AB","Disc menu EN" "T3A","LC0724","LC0724","CALGARY LCD 11","218","22","","","HAI025 1-AB","Disc menu EN"
to this:
"T3A","LC0721","LC0721","CALGARY LCD 11","60","197","","","1-AB HAI025","Disc menu EN" "T3A","LC0724","LC0724","CALGARY LCD 11","218","22","","","1-AB HAI025","Disc menu EN"
Note: I tried to keep the spirit of your original expression, because I don’t know how else your data looks.
BTW, not sure why you escaped the
H
(as\H
) because\H
doesn’t meanH
, it means “a single character that is not horizontal whitespace”. -
@alan-kilborn said in Search & Replace regex:
(?-is)“(HAI…) (.*?)”
Tx Alan
Your solution works perfectly. Very very new at using notepad++ to modify data. Usually a database (access, foxpro, filemaker) or excel. But the supplier (Canada Post) gave me csv files, it is much simpler to keep them almost as they were supplied to me.
Tx
Yves