Community
    • Login

    Use regex to replace backspace by underscore

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    7 Posts 3 Posters 8.5k 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.
    • Mauricio SalazarM
      Mauricio Salazar
      last edited by

      Hi everybody I have a csv file in which I would like to make the following replacement:

      Input:
      Word, Word

      Output:
      Word_Word

      I want to replace words with the following characteristics:

      1. Longer than four characters
      2. The first word ends with a comma
      3. There is a backspace between the words

      I tried this regular expression with the TextFX, but I did not work:

      Find:
      ^[A-Za-z],{3,23}$\b^[A-Za-z]{3,23}$

      Replace:
      ^[A-Za-z],{3,23}$[_]^[A-Za-z]{3,23}$

      Thank you

      gerdb42G 1 Reply Last reply Reply Quote 0
      • gerdb42G
        gerdb42 @Mauricio Salazar
        last edited by

        With NPPs Search&Replace you would use ^(\w{5,}),\x08(.*)$ to search and $1_$2 for replacement. This will search for any word at the beginning of a line which is 5 or more characters long and is followed by a colon followed by a backspace. Both the word and the remainder of the line are grouped. In the replacement, the word followed by an underscore followed by the rest of the original line is used.

        You may want to read about the Regular Expression syntax here for searching and here for replacing.

        1 Reply Last reply Reply Quote 0
        • Mauricio SalazarM
          Mauricio Salazar
          last edited by Mauricio Salazar

          Thank you for your help, but I wonder if I am applying the regex correctly.

          http://postimg.org/image/tb98dqnf7/

          As you see in the image I did not change. With “NPPs Search&Replace” you meant a plug in.

          Thank you

          1 Reply Last reply Reply Quote 0
          • dailD
            dail
            last edited by

            From your image, it doesn’t look like there is a backspace after the comma.

            img

            1 Reply Last reply Reply Quote 0
            • Mauricio SalazarM
              Mauricio Salazar
              last edited by

              You are right, is was a noob error backspace ≠ whitespace,. So I followed this post, link, that suggest using: (\s).

              Alt text

              Could you please help me changing the regex from backspace to whitespace?

              Best Regards

              1 Reply Last reply Reply Quote 0
              • dailD
                dail
                last edited by dail

                ^(\w{5,}),\s(.*)$

                Instead of \x08 which represents 1 backspace character you just use \s which is a single whitespace chracter.

                1 Reply Last reply Reply Quote 0
                • Mauricio SalazarM
                  Mauricio Salazar
                  last edited by

                  Thank you, it worked well

                  Best Regards

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