How do I remove all non-ASCII characters with regex and Notepad++?
Solution 1
This expression will search for non-ASCII values:
[^\x00-\x7F]+
Tick off 'Search Mode = Regular expression', and click Find Next.
Source: Regex any ASCII character
Solution 2
In Notepad++, if you go to menu Search → Find characters in range → Non-ASCII Characters (128-255) you can then step through the document to each non-ASCII character.
Be sure to tick off "Wrap around" if you want to loop in the document for all non-ASCII characters.
Solution 3
In addition to the answer by ProGM, in case you see characters in boxes like NUL or ACK and want to get rid of them, those are ASCII control characters (0 to 31), you can find them with the following expression and remove them:
[\x00-\x1F]+
In order to remove all non-ASCII AND ASCII control characters, you should remove all characters matching this regex:
[^\x1F-\x7F]+
Solution 4
To remove all non-ASCII characters, you can use following replacement: [^\x00-\x7F]+
To highlight characters, I recommend using the Mark function in the search window: this highlights non-ASCII characters and put a bookmark in the lines containing one of them
If you want to highlight and put a bookmark on the ASCII characters instead, you can use the regex [\x00-\x7F]
to do so.
Cheers
Solution 5
To keep new lines:
- First select a character for new line... I used #.
- Select replace option, extended.
- input \n replace with #
- Hit Replace All
Next:
- Select Replace option Regular Expression.
- Input this : [^\x20-\x7E]+
- Keep Replace With Empty
- Hit Replace All
Now, Select Replace option Extended and Replace # with \n
:) now, you have a clean ASCII file ;)
Related videos on Youtube
Texh
Updated on February 12, 2021Comments
-
Texh over 3 years
I searched a lot, but nowhere is it written how to remove non-ASCII characters from Notepad++.
I need to know what command to write in find and replace (with picture it would be great).
If I want to make a white-list and bookmark all the ASCII words/lines so non-ASCII lines would be unmarked
If the file is quite large and can't select all the ASCII lines and just want to select the lines containing non-ASCII characters...
-
Mike M over 10 yearsand just in case it isn't obvious, if you remove the "^" you are searching the ASCII lines
-
Alex almost 10 yearsThis works well, but doesn't show all results in a list and no "replace" option
-
FoamyGuy over 9 yearsWorks good, but I had to set
Encoding->Encode in ANSI
. Was unable to find anything otherwise. -
Unihedron over 9 yearsValues from
\x00
and\x1F
are already matched in the answer by ProGM. -
brunorey over 9 yearsThey're matched as values you'd like to keep. I was just suggesting this in case you want to get rid of them.
-
Teson almost 9 yearsWorks perfectly in netbeans with its regexp-search option (asterix-button)
-
fgb over 8 yearsThe last example should begin at 20 to exclude the unit separator character. Maybe exclude 7F as well as it's a control character too.
-
hyena over 7 yearsif you want to copypaste the search expression [^\x00-\x7F]+
-
Kasim Husaini about 7 yearsZapping all characters replaces all type of punctuation marks with ###. The solution I would expect is: Replacing “ & ” with ". Replacing ‘ & ’ with '. etc.
-
Raghav over 6 yearsIt works fine, however, the tool replaces funny chars with one # char and not three. please take note.
-
yashhy over 6 yearsworks in VS-Code, don't forget to click Regex search option!
-
Steffen Winkler over 6 yearsIf you want to keep \r and \n - carriage return and linefeed characters - you can use this regex: [\x00-\x09\x0B-\x0C\x0E-\x1F]+
-
Steffen Winkler over 6 yearsIf you want to keep \r and \n - carriage return and linefeed characters - you can use this regex: [\x00-\x09\x0B-\x0C\x0E-\x1F]+
-
Peter Mortensen almost 6 yearsThe Text FX plugin is deprecated and may not even be readily available anymore. See e.g. TextFX's Future - "When the list grows long enough, it will become practical to bid farewell to an aging workhorse that has served the community well."
-
oldboy over 5 yearsis there any way to automate this??
-
Anatoly Alekseev over 5 yearsWhy can't this expression find single characters? there must be at least 2 such to be detected with it in Notepad++
-
Pablo Adames almost 5 yearsBrilliant! I removed all pesky non-ASCII characters using the qdap R package using:
mgsub("[^\x1F-\x7F]+", "", text_vector, fixed = FALSE)
-
Jean-Francois T. over 4 yearsNeat... because I always forget the regex for the non-ASCII and have to Google it each time to go back to this page :)
-
Toto over 3 yearsDo you really want to do that for ALL non ASCII characters? They are thousands!
-
Jason C over 2 yearsSo the trick with this is when you press find here it selects the character. Then you just go to the Edit menu and pick Replace, and Notepad++ always fills the "find" box in with the current selection, which will be the character you found. So you can do the rest of the find/replace in the normal dialog.