Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing non-Latin characters from a string

I'm trying to remove non-Latin characters from a string with Javascript. I'm using the following code:

text.replace(/[\u0250-\ue007f]/g, '')

I first thought it was working fine, until I discovered it also removes the 'f' character from the string. Any suggestions?

like image 646
Bjorn Avatar asked Nov 28 '12 14:11

Bjorn


People also ask

How do I strip a character from a string?

You can remove a character from a Python string using replace() or translate(). Both these methods replace a character or string with a given value. If an empty string is specified, the character or string you select is removed from the string without a replacement.


1 Answers

Try this:-

 text.replace(/[\u0250-\ue007]/g, '');
like image 152
Rahul Tripathi Avatar answered Oct 29 '22 13:10

Rahul Tripathi