Search code examples
regexreplacenotepad++

How to keep parts of the text you replace in Notepad++


I would like to replace all new lines after lower cases with space. Regex: "[a-z]\n" and only replace the \n with space. How do I keep the lower case, when I replace it?


Solution

  • Use Capture groups.

    For your example, it would look like this:

    Replace ([a-z])\n with $1

    $n represents the content of the nth capture group. Capture groups are created by putting braces ( ) arround a part of the regex.

    Windows uses \r\n for newlines, so for here is a regex that supports both styles of line endings by making the \r optional: ([a-z])\r?\n