0

I have a text file with several hundred lines similar to below:

Here are some examples lines,\Nthis text needs to strip out\Ncertain,
Here are some examples lines.
Here are some.
Here are some examples lines,\Nthis text needs to.
Here are some examples lines,\Nthis text needs to strip out\Ncertain,

The character I want to remove is the second literal \N

I've looked at macros, but I think macros only record what is typed into the page.

Is there any automated search replace that I can use in Notepad++ to replace the second \N with white space? (The first \N should remain.)

1

In the search and replace dialog select "Regular expressions" and find the following:

(\\N.*)\\N

Replace with: \1 (Note that there is a space after the \1)

  • So, on each line, you have two "\N". Are both of those line breaks, or actual characters inside the text? And you want to remove only the second one on each line? – Kard Nails Mar 21 '14 at 15:34
  • Yes, thats correct. Literal \N means it is \ and N. – rrrfusco Mar 21 '14 at 15:35
  • Are the examples accurate? Is there always a comma before the first "\N"? – Kard Nails Mar 21 '14 at 15:36
  • Not necessarily commas. The first \N will fall between two words. – rrrfusco Mar 21 '14 at 15:37
  • I have edited my answer. I tested it and it works, but always have a backup just in case. – Kard Nails Mar 21 '14 at 15:44
2

Search and replace in Regular Expression mode for the following:

^(.*?\\N.*?)\\N

Replace with

\1 

Explanation:

^ indicates the match must start at the beginning of a line.
.*?\\N matches all text in the line up to and including the first literal \N.
.*? matches everything up to the next literal \N.
Everything matching the pattern inside the parentheses is returned by \1.

  • What's the difference between your regex and his? – rrrfusco Mar 21 '14 at 15:48
  • 2
    This one uses "lazy" or "non-greedy" wildcard matching (the extra question marks). This makes sure the match will always remove the second literal \N. The other solution will match any two literal \Ns in the same line and remove second. This may work for you, but if your data includes any lines with more than 2 literal \Ns, it will likely remove the wrong one. – Excellll Mar 21 '14 at 15:52
  • I get this error when I press replace or replace all: can't find the text "^(.*?\\N.*?)\\N" – rrrfusco Mar 21 '14 at 15:58
  • @rrfusco I don't have Notepad++ on this computer, but I suspect it may be an issue with your search settings. I'm not much help in that regard until I have NP++ in front of me. All I can suggest is try placing the cursor at the start of the file and make sure it is set to search the entire document. – Excellll Mar 21 '14 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.