Community
    • Login

    Search & Replace regex

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 2 Posters 173 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Yves DavignonY
      Yves Davignon
      last edited by Yves Davignon

      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 \1

      Results:

      “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

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @Yves Davignon
        last edited by

        @yves-davignon

        Why not just change it to?:

        Find: (?-is)"(HAI...) (.*?)"
        Replace: "\2 \1"
        Search mode: Regular expression

        That 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 mean H, it means “a single character that is not horizontal whitespace”.

        Yves DavignonY 1 Reply Last reply Reply Quote 2
        • Yves DavignonY
          Yves Davignon @Alan Kilborn
          last edited by

          @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

          1 Reply Last reply Reply Quote 1
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors