Search code examples
notepad++space

Remove the Space from [A-Za-z]+(\s[A-Za-z]+)


I want to remove the space between the two words only. To find these words in the file [A-Za-z]+(\s[A-Za-z]+) this expression works perfectly. But now, I want to know with which regular expression should I replace this to remove the space.

eg. Original: tables, two tables, chair

What I want: tables, twotables, chair


Solution

  • Here is a way to go:

    • Ctrl+H
    • Find what: (?<=[a-z])\h+(?=[a-z])
    • Replace with: LEAVE EMPTY
    • UNcheck Match case
    • check Wrap around
    • check Regular expression
    • Replace all

    Explanation:

    (?<=[a-z])  : lookbehind, make sure we have a letter before
    \h+         : 1 or more horizontal spaces (ie. space or tabulation)
    (?=[a-z])   : lookahead, make sure we have a letter after
    

    Result for given example:

    tables, twotables, chair
    

    Edit:

    For unknown reason, it doesn't work when we use Replace instead of Replace all.

    We have to use:

    • Find what: ([a-z])\h+([a-z])
    • Replace with: $1$2