javascript – Return only alphanumeric and normal space between words even for RTL

For any JavaScript environment that supports ECMAScript 2018+ standard, you can use .replace(/[^p{L}p{N}]+/gu, ” “) where /[^p{L}p{N}]+/gu matches multiple occurrences (g) of one or more (+) characters that are not Unicode letters (p{L}) and digits (p{N}). The u flag enables the use of Unicode property classes like p{…}. function simplifyUserName(name) { return name.toLowerCase().replace(/[^p{L}p{N}]+/gu, ” “).trim(); … Read more