• Login
Community
  • Login

Use regex to replace backspace by underscore

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
7 Posts 3 Posters 8.6k 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.
  • M
    Mauricio Salazar
    last edited by Sep 23, 2016, 4:27 AM

    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

    G 1 Reply Last reply Sep 23, 2016, 7:57 AM Reply Quote 0
    • G
      gerdb42 @Mauricio Salazar
      last edited by Sep 23, 2016, 7:57 AM

      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
      • M
        Mauricio Salazar
        last edited by Mauricio Salazar Sep 23, 2016, 9:04 PM Sep 23, 2016, 9:03 PM

        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
        • D
          dail
          last edited by Sep 23, 2016, 9:45 PM

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

          img

          1 Reply Last reply Reply Quote 0
          • M
            Mauricio Salazar
            last edited by Sep 24, 2016, 12:44 AM

            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
            • D
              dail
              last edited by dail Sep 24, 2016, 1:09 AM Sep 24, 2016, 1:09 AM

              ^(\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
              • M
                Mauricio Salazar
                last edited by Sep 24, 2016, 1:21 AM

                Thank you, it worked well

                Best Regards

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