Javascript replaces special characters

Is it possible to translate special characters like ®, ü, etc. using javascript string replacement function?

+3
source share
5 answers

yes, and as simple as it can be:

'®'.replace('®','anything');
+2
source

Of course!!

Running this in a Firebug console

"®ü".replace(/[®ü]/g,"replaced")

came back

"replacedreplaced"

You can also do

"®ü".replace(/[\xAE\xFC]/g,"Wohoo! ");

which returns

"Wohoo! Wohoo! "

A good hexadecimal search page can be found at http://www.ascii.cl/htmlcodes.htm


Example

running jQuery on this page

$(".post-text").text().replace(/®/g," ******** ")

returns

" is it possible to translate special characters like ******** , ü etc with javascript 
String replace function? Use this syntax... string.replace(/\xCC/g/,''); Where 'CC' is 
the hex character code for the char you are wanting to replace. In this example I am 
replacing with empty string ''. yes, and is as simple as can be: ' ******** '.replace('
 ******** ','anything'); Sure is! Running this in the Firebug console " ******** ü".
replace(/[ ******** ü]/g,"replaced") returned replacedreplaced "
+5
source

...

string.replace(/\xCC/g,'');

"CC" - char, . ''.

, , :

string.replace(/[\xAE\xFC]/g,'');
+1

(, , , Google, - , / ):

, . , , , ( , ), " ", . , .

, , , .

, , , 3 :

, encodeURIComponent. escape encodeURI/encodeURIComponent? .

, , . , http://www.the-art-of-web.com/javascript/escape/ http://shebang.brandonmintern.com/foolproof-html-escaping-in-javascript/ ( verbose, , )

0

JavaScript,

var a1 = $('#txt').val().replace(/[^\x30-\x39\x41-\x5A\x61-\x7A\x20\x26\x28\x29\x2C\x27\x22\x2E\x2F\x26\x40\x5C\x7C\x3A\x2D]/g, ''); 

, 0-9A-Za-z &(), '"./& @\|: - , ..

@alberto-Zaccagni . , :)

-1

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


All Articles