11

I have a very long string, with with data split up by a "|" as a delimiter. It looks something like this:

some data||some data||||

I want to split this line by line, to look like this:

some data|
|
some data|
|
|
|

But, by using replace | with |\r\n, I end up with something like this:

s
o
m
e

d
a
t
a
|
|
etc.

How do I split this the way I want to in NPP?

3 Answers 3

9

Use the search string:

\|

With the replacement string:

\|\r\n

You are running the command in REGEX mode, and the | in the search string will be picked up as a REGEX operator, it simply needs to be escaped.

5

Just use Extended Search Mode instead Normal or Regular expression ones.

NPP extended search

3
  • For those who are wondering(just like i was), Search Mode is found on the same pop-up screen where you do the Replace, at the bottom left of the window, at the time of this comment. 3 choices: Normal(default), Extended, and Regular Expression. Jun 4, 2020 at 13:14
  • @jumping_monkey I hope that answer is informative enough now.
    – g2mk
    Jun 7, 2020 at 14:59
  • A picture tells a thousand words, well done. Although your find/replace should be the other way round to answer the OP's question, i can give you a +1 as it is informative enough to help others. Cheers mate. Jun 8, 2020 at 0:24
1

I want to replace | with |<cr><lf>

Note: | is a special character (alternation operator) in a regular expression, so it needs to be escaped using the escape character \.

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

  • Set "Find what" to \|

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

  • Enable "Regular expression"

  • Click "Replace All"

Image

Before:

some data||some data||||

After:

some data|
|
some data|
|
|
|

Further reading

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .