• Login
Community
  • Login

add text before the 2nd last space in each line?

Scheduled Pinned Locked Moved General Discussion
5 Posts 2 Posters 862 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.
  • G
    gifthubbro
    last edited by Nov 2, 2020, 7:06 PM

    I want to add a comma before the 2nd last time in each line of text in notepad ++, heres an example if what I mean : house, Road, westworld, Co. London H509 50565

    so I want to add the comma after London, to make it appear like this: house, Road, westworld, Co. London, H509 50565

    thanks!

    1 Reply Last reply Reply Quote 0
    • T
      Terry R
      last edited by Nov 2, 2020, 7:13 PM

      @gifthubbro said in add text before the 2nd last space in each line?:

      heres an example if what I mean : house, Road, westworld, Co. London H509 50565

      Are you able to confirm that the last piece “H509 50565” exists on all lines. Obviously not those exact characters, but that there are 2 words (a word here is defined as a string of non-blank characters) that need separating by adding the comma on every line. Without that assumption is might be difficult to decide where to place the comma.

      Terry

      G 1 Reply Last reply Nov 2, 2020, 7:16 PM Reply Quote 0
      • G
        gifthubbro @Terry R
        last edited by Nov 2, 2020, 7:16 PM

        @Terry-R thats right all the lines are two words, where I need to insert a comma before these last two words

        1 Reply Last reply Reply Quote 0
        • T
          Terry R
          last edited by Terry R Nov 2, 2020, 7:18 PM Nov 2, 2020, 7:17 PM

          @gifthubbro said in add text before the 2nd last space in each line?:

          so I want to add the comma after London

          So that being true, try this.
          Replace function:
          Find What:^(.+)((\h\w+){2})$
          Replace With:\1,\2

          See if that works for you.

          Terry

          G 1 Reply Last reply Nov 2, 2020, 7:18 PM Reply Quote 3
          • G
            gifthubbro @Terry R
            last edited by Nov 2, 2020, 7:18 PM

            @Terry-R thanks that worked!

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