Find and replace tabs or newline characters in Webstorm - replace

I want to delete all my newline and tab characters in a file using Webstorm. How do I do this?

When using the find/replace tool, make sure Regex is checked and then use the escape character codes to locate the necessary characters:
\n = newline
\t = tab
if you leave the replace line blank and select replace all, you can then delete all instances of the specified character.

Related

How to Remove Single Blank Line Using Notepad++ Regex

I want to remove just the last line in a file if it's a line containing nothing. I am using Notepad++.
Details
Say I have a text file open in Notepad++. If the last line of a file is the empty string, I want to remove it. I want to do this using Notepad++'s native find/replace functionality, with regexes.
Use Case
I often encounter this case after I copy a file from Visual Studio to Notepad++. The reason for searching how to do it with a regex is: when recording a macro in Notepad++ it's more stable to use a regex find/replace than just manually deleting a character. The manual delete might be sensitive to file length.
Ctrl+H
Find what: \R\z
Replace with: LEAVE EMPTY
CHECK Regular expression
Replace
Explanation:
\R # any kind of linebreak (i.e. \r, \n, \r\n)
\z # end of file
Screen capture (before):
Screen capture (after):
The solution is to search for this regex: \r\n$(?!\r\n) and replace it with nothing (the empty string).

Regex for matching linefeed with next character ignored

I am trying to select linefeed and remove them in a comma separated file via REGEX search in notepad++, the criteria for matching linefeed is that it should not followed the character "I" in the next line.
Example:-
Output should be:-
Tip: don't use images as we can't copy past them
replace
\r\n(?!|)
with nothing
Note that I assume your are using windows linebreaks \r\n

Notepad++ weird bug? when replace a huge string

I'm getting a CR LF characters after replacing a huge string with Notepad++.
Moreover, The string add a line break in places which I didn't ask.
Weird...
Here is the print screen:
Those CR LF character haven't been there before I was using string replace (or they where hidden? and if so why the string replace revealed them?)
Is there is a quick (regex?) solution to remove them ?
Is there any quick (regex?) solution to remove any characters that is NOT [a-z] [A-Z] [0-9] ["|'] OR NON UTF-8 characters ?
You can just replace \r\n with nothing, and that will remove the line breaks.
To remove any character that is not [a-z][A-Z][0-9]["|'], replace [^A-Za-z0-9"|'] with nothing. But be careful that you've thought of everything you do want to keep: spaces, tabs, other punctuation, etc.

search and replace \n or \t with and empty space

Can anyone teach me how to search and replace \n or \t and replace it with an "empty" space? I tried using the search and replace in GEDIT, but it just doesn't change. I'm using GEDIT by the way.
sample:
Hi I am \n\t\t\t\t\t\t\t\t\ John Doe`n\t\t\t\t\t` I live in BLAH BLAH.
Output:
Hi I am John Doe I live in BLAH BLAH.
How to do this?
Although this thread is now 5 years old the answers do not really suffice so here is a working answer;
The most simple way to replace newline and tab characters (\n & \t) use the backslash to tell gEdit search you don't want to search for an actual newline but for the chars that represent a new line;
\\n or \\t
Replace \s+ with a single space.
\s means 'any white space character'
+ means 'one or more'
So \s+ means 'one or more white space characters'. You'd want to replace those with a singe space.
Replace text in gedit
Open the Replace tool by clicking Search ▸ Replace or press Ctrl+H.
Enter the text that you wish to replace into the 'Search for:' field.
Enter the new, replacement text into the 'Replace with:' field.
Once you have entered the original and replacement text, select your
desired replacement options:
To replace only the next matching portion of text, click Replace.
To replace all occurrences of the searched-for text, click Replace
All.
Source

regex in Notepad++ to remove blank lines

I have multiple html files and some of them have some blank lines, I need a regex to remove all blank lines and leave only one blank line.. So it removes anything more than one blank line, and leave those that are just one or none (none like in having text in them).
I need it also to consider lines that are not totally blank, as some lines could have spaces or tabs (characters that doesn't show), so I need it to consider these lines with the regex to be removed as long as it is more than one line..
Search for
^([ \t]*)\r?\n\s+$
and replace with
\1
Explanation:
^ # Start of line
([ \t]*) # Match any number of spaces or tabs, capture them in group 1
\r?\n # Match one linebreak
\s+ # Match any following whitespace
$ # until the last possible end of line.
\1 will then contain the first line of whitespace characters, so when you use that as the replacement string, only the first line of whitespace will be preserved (excluding the linebreak at the end).
This worked for me on notepad++ v6.5.1. UNICODE windows 7
Search for: ^[ \t]*\r\n
Replace with: nothing, leave blank
Search mode: Regular expression.
search for (\r?\n(\t| )*){3,}, replace by \r\n\r\n, check "Regular expression" and ". matches newline".
Tested with Notepad++ 6.2
This will replace the successive blank lines containing white spaces (or not) and replace it with one new line.
Search for
(\s*\r?\n){3,}
replace with
\r\n
You can find it yourself what you need to replace with
\n\n OR \n\r\n or \r\n\r\n etc ... now you can even modify your regular expression ^([ \t]*)\r?\n\s+$ according to your need.
I tested any of the above suggestions, always was either too less or to much deleted. So that either you got no blank line where at least one was beforehand or deleted not enough (whitespaces was left, etc.). Unfortunately I cannot write comments yet. Tested both with 6.1.5 and updated to 6.2 and tested again. depending on how mayn files there are, I would suggest use
Edit->Blank Operations->Trim trailing whitespace
Followed by Ctrl+A and
TextFX -> TextFX Edit -> Delete surplus blank lines
A Macro I tried to record didn't work. Theres even a macro for just remove trailing whitespace (Alt+Shift+S, see Settings | Shortcut Mapper... | Macros). There's a
Edit->Blank Operations->Remove unnecessary EOL and whitespace
but that deletes every EOL and puts everything in a single line.
In notepad++ v8.4.7 there is the option:
Edit > Line Operations > Remove Empty Lines (Containing Blank characters)
or
Edit > Line Operations > Remove Empty Lines
So there is no need to use a regular expressions for this. But this only works for one file at a time.
I looked for ^\r\n and click "Replace All" with nothing (empty) in "Replace with" textbox.