How to reliably cut invisible characters that break code?

I am trying to create a bookmarklet and got this problem that I only managed to find out: the \u8203 that Chrome uselessly tells me in my code block (when pasting into the JS console) `` Invalid ILLEGAL character ''.

Fortunately, Safari was the one who told me that it was \u8203 .

I am editing the code in the Sublime Text 2 editor and somehow copying it and from it (I also tried TextEdit) was unable to delete it.

Is there any website somewhere that will share all non-ASCII characters?

When I try to save as ISO 8859, but it will save it as UTF-8 "due to unsupported characters".

... Yes. what a point. Get rid of my unsupported evil characters.

What should I do? Edit my file in a hex editor?

FYI I actually solved it by re-typing the code (which came from this site, by the way).

+6
source share
4 answers

Well, the easiest way I can come up with is to use sed

 sed -i 's/[^[:print:]]//g' your_script.js // ^^^^^ this can also be 'ascii' 

or using tr

 tr -cd '\11\12\15\40-\176' < old_script.js > new_script.js 
+4
source

Is there any site somewhere that will share all characters except ASCII?

You can use this website

You can recreate the site using this code:

 <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>- jsFiddle demo</title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="/css/normalize.css"> <link rel="stylesheet" type="text/css" href="/css/result-light.css"> <style type="text/css"> textarea { width: 800px; height: 480px; outline: none; font-family: Monaco, Consolas, monospace; border: 0; padding: 15px; color: hsl(0, 0%, 27%); background-color: #F6F6F6; } </style> <script type="text/javascript"> //<![CDATA[ $(function () { $("button").click(function () { $("textarea").val( $("textarea").val().replace(/[^\u0000-\u007E]/g, "") ); $("textarea").focus()[0].select(); }); }); //]]> </script> </head> <body> <textarea></textarea> <button>Remove</button> </body> </html> 
+11
source

you can use regex to filter everything from 0-127. For example, in javascript:

 text.replace(/[^\x00-\x7F]/g, "") 

x00 = 0, x7f = 127

+4
source

Non-technical solution: paste the text into a new email message in Gmail and press Tx (clear formatting in the formatting menu). Worked for me.

0
source

Source: https://habr.com/ru/post/920856/


All Articles