How can I wrap text in Notepad++, but leave paragraph lines intact?
Example:
The original text looks like this:
This
is
paragraph
one.
This
is
paragraph
two.
I would like the text to look like this:
This is paragraph one.
This is paragraph two.
But currently, when I go to Edit > Blank Operations > Remove Unnecessary Blank and EOL, the text ends up with no paragraph line in between, like this:
This is paragraph one. This is paragraph two.
How can I fix this?
Thank you.
You may try the following find and replace, in regex mode:
Find: ([^.\s])\r?\n
Replace: $1[ ]
Demo
The regex pattern ([^.\s])\r?\n will match and capture any letter which appears before a CR?LF character, so long as that character is not a full stop. It then replaces with that same character, followed by just a single space, thereby removing/replacing the original CR?LF.
This will replace every single linebreak with a space.
Ctrl+H
Find what: [^\r\n]+\K\R(?!\R)
Replace with: # a space
CHECK Wrap around
CHECK Regular expression
Replace all
Explanation:
[^\r\n]+ # 1 or more non linebreak
\K # forget them
\R # any kind of linebreak (i.e. \r, \n, \r\n)
(?!\R) # negative lookahead, make sure we haven't another linebreak after
Screenshot (before):
Screenshot (after):
In Windows 10 I use a text editor (I'd like not to point out a particular one but I usually use Visual Studio Code AKA "VSCODE").
I need a way to delete all blank lines whatsoever only with regex after I matched them with this code:
^\s*$
After I match the lines themselves, how is it possible to delete the lines?
AFAIK, regex only edit lines, not deleting lines or adding lines.
I desire a way to delete all matched (empty).
Hitting "Enter" or "Delete" in the empty "replace" box doesn't delete lines:
You were close. You were missing the new line character in your regex. This worked for me:
^\s*$\n
Without the newline character, you are matching the blank line itself which you then replace with nothing but you've left the newline character so it still leaves an empty line in place.
I installed JD-GUI to retrieve my code from a jar file. Everything works fine, except JD-GUI automatically adds annoying comments like this:
Any way I can remove them? I don't understand regex.
Using Eclipse:
Go to Edit > Find/Replace...
Use this regular expression in the Find box: ^/\* [0-9 ]{3} \*/
^ match start of line.
/\* match start of comment
[0-9 ]{3} match exactly three digits/spaces
\*/ match end of comment
Make sure the Replace box is empty.
Make sure the Regular expressions checkbox is selected.
Click Replace All
Use CTRL+H. Within "File Search" > "Search string", check "Regular expression" and use one of the regex given by the other answers.
Then use "Replace..." to replace them all with nothing.
Use the utility sed to search for a regex and replace with an empty string. Here is a gist that should get you started with using it.
Since you don't understand regex, I'll help you out with it: /^\/\* \d+ \*\//gm will find every comment block that starts at the beginning of a line and contains a line number.
Here's how it works:
/ is the start of the regex
^ matches the begnning of the line
\/\* finds the opening /* of the comment
(space) finds the space before the line number
\d+ finds any number of digits
(space) finds the space after the line number
\*\/ finds the ending */ of the comment
/gm ends the regex and flags this as a global, multiline search
I have a text file with multiple lines such as:
amanda: foo
robert: bla
amanda: bar
peter: da
I'd like to remove all lines with amanda. I use ctrl-s and kill each line individually. Is possible to remove all lines at once?
M-x delete-matching-lines. It's possible to use regular expression.
One way is to use query-replace-regexp with a regular expression of ^.*amanda.*$ to an empty string.
Although #Marcos's answer is idiomatic one (you should use it), let's explore other variants. Let's say you have a text buffer and you want to delete a line containing li in it:
Vladimir
Ilich
Ulyanov
Remember, that ^ matches beginning of line and $ end of line in regex. $ doesn't touch the newline character after the line, so replace with regex ^.*li.*$ will produce an empty line, as per #ataylor's answer:
Vladimir
Ulyanov
For some reason it's impossible to match before ^ and after $ in regex, therefore \s-^.*li.*$ nor ^.*li.*$\s- won't work. Note, \s- matches any whitespace character, (i.e. space, tab, newline and carriage return), so intuitively the regexes should've deleted the newline too, as newline is the only possible whitespace character before ^ or after $. To match exactly newline, you should enter it verbatim, C-q C-j by default. Emacs frequently denotes the newline in separate font color as ^J, it's not a sequence of ^ and J, but a single character, please pay attention.
Therefore to delete a line containing li, you could run command query-replace-regexp on string ^.*li.*^J, where ^J is newline:
Vladimir
Ulyanov
Suppose you have this file:
x
a
b
c
x
x
a
b
c
x
x
and you want to find the sequence abc (and select the whole 3 lines) with Notepad++ . How to express the newline in regex, please?
Notepad++ can do that comfortably, you don't even need regexes
In the find dialogue box look in the bottom left and switch your search mode to Extended which allows \n etc.
As odds on you're working on a file in windows format you'll be looking for \r\n (carriage return, newline)
a\r\nb\r\nc
Will find the pattern over three lines
Update 18th June 2012
With the new Notepad++ v6, you can indeed search for newlines with regexes. So you can just use
a\r\nb\r\nc
even with regular expressions to accomplish what you want. Note \r\n is Windows encoding of line-breaks. In Unix files, its just \n.
Unfortunately, you can't do that in Notepad++ when using regex search. Notepad++ is based on the Scintilla editor component, which doesn't handle newlines in regex.
You can use extended search for newline searching, but I don't think that will help you search for 3 lines.
More info here.
Update: Robb and StartClass0830 were right about extended search. It does work, but not when using regular expressions search.
^a\x0D\x0Ab\x0D\x0Ac
This will work \x0D is newline and \x0A is carriage return. Assumption is that each line in your file ends with ascii 10 and 13.
I found a workaround for this.
Simply, in Extended mode replace all \r\n to a string that didn't exist in the rest of the document eg. ,,,newline,,, (watch out for special regexp chars like $, &, and *).
Then switch to Regexp mode, do some replacements (now newline is ,,,newline,,,).
Next, switch to Extended mode again and replace all ,,,newline,,, to \r\n.
For Notepad 6 and beyond, do this as a regular expression:
Select Search Mode > Regular expression (w/o . matches newline)
And in the Find what Textbox : a[\r\n]b[\r\n]+c[\r\n]
or if you are looking at the (Windows or Unix) file to see its line breaks as \r\n or \n then you may find it easier to use Extended Mode:
Select Search Mode > Extended (\n, \r, \t, \0, \x...)
And in the Find what Textbox for Windows: a\r\nb\r\nc\r\n
Or in the Find what Textbox for Unix: a\nb\nc\n
Wasn't clear if the OP intent is to select the trailing line return (after the 'c') as well, as would be necessary to remove the lines.
To not select the trailing line return, as appropriate for replacing with a non-empty string, simply remove the final line return from the matching statement.
Note that if there should be a match on the last line of the string, without a matching trailing line return, the match fails.
a\r\nb\r\nc works for me, but not ^a\x0D\x0Ab\x0D\x0Ac
Hmm, too bad that newline is not working with regular expressions. Now I have to go back to Textpad again. :(
Select Search Mode Which is
Extended (\n, \r, \t, \0, \x...)
\n is new line and such
This is Manuel
Find: "(^a.$)\r\n(b.)\r\n^(c.*)$" - pickup 3 whole lines, only storing data
Replace with: "\1\2\3" - Put down (replay) data
Works fine in Regex with Notepad++ v7.9.5
Place holders: ^ Start and $ End of line can be inside or out of ()store as shown, though clearly not necessary in given example. Note "[^x]" is different - here "^" is "NOT".
Advantage of storing and replay allows much more complicated pattern match without having to type in again what you want to end up with, and even change of replay: "\2\3\1" for "bca"
I have run accross this little issue when the document is windows CR/LF
If you click the box for . to match newlines you need .. to match CR/LF so if you have
<blah><blah>",
"<more><blah>
you need to use ",.." to match some string comma cr/lf another string
In Notepad++ you can also try highlighting the desired part of the text and then pressing CTRL+J.
That would justify the text and thus removing all line endings.