Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter non-Alpha characters for multiple languages

Tags:

javascript

I want to write a regex to remove all non alpha characters, as follows:

björn -> björn
Barry's -> barrys
Who? -> who
Cibé? -> cibé
I'd -> id
ice-cream -> icecream
No!!! -> no
[{brackets}] -> brackets
~inv3rse -> invrse

and to convert all characters to their lowercase versions. How do I do this for all languages or at least for European languages using the Latin script?

like image 765
Baz Avatar asked Mar 19 '26 02:03

Baz


1 Answers

str.toLowerCase().replace(/[^a-z]/gi,'');

this will convert everything to lowercase, then replace everything that isn't an alphabetic character (a-z) to the empty string, essentially removing them. in order to keep certain other characters (like e with an accent mark) just add that symbol to the regex.

like image 60
gr3co Avatar answered Mar 20 '26 18:03

gr3co



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!