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\Hdoesn’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
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login