Use regex to replace backspace by underscore



  • 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



  • 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.



  • 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



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

    img



  • 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



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

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



  • Thank you, it worked well

    Best Regards


Log in to reply