Replace every nth instance of a character with a new line in Notepad++

Find: ([^\|]*\|[^\|]*)\|
Replace to: \1\n


I want to replace every second instance of | with a new line

  • Menu "Search" > "Replace" (or Ctrl + H)

  • Set "Find what" to (.*?\|.*?)[\|]

  • Set "Replace with" to \1\r\n

  • Enable "Regular expression"

  • Click "Replace All"

    enter image description here

Before:

Name1|Value1|Name2|Value2|Name3|Value3

After:

Name1|Value1
Name2|Value2
Name3|Value3

Notes:

  • The above assumes you are editing a text file with Windows EOLs, \r\n.

  • If you are using files with different EOLs you can convert them to Windows EOLs using Menu "Edit" > "EOL Conversion".

  • If you aren't working with Windows EOL, and you don't wish to convert them, use the following instead:

    • Use \n instead of \r\n for Unix/OS X EOLs

    • Use \r instead of \r\n for Mac OS (up to version 9) EOLs


Further reading

  • Notepad++: A guide to using regular expressions and extended search mode