D
D
DemonIa2020-08-25 15:25:28
JavaScript
DemonIa, 2020-08-25 15:25:28

How to select everything except letters and numbers and umlaut in js with a regex?

There is a line, for example in Turkish (same story with Finnish, German, etc.)
Here: Türk and Türk

I need to remove all characters that are not a letter or a number. I understand that ü is a unicode character and I need to add the /u flag so that it is recognized as a letter and not as a special character. symbol.
I am writing a regular expression: And indeed, everything works: spaces fall under the condition, and will be replaced by emptiness (i.e. removed), and the umlaut / will remain untouched: But if the same trick is performed in the browser console, then the umlaut character is deleted along with spaces. Why?'Türk and Türk'.replace(/\W/gu, '');

5f4502fd3102e098365230.png

5f4502e4c094d974208021.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2020-08-25
@DemonIa

.replace(/[^\p{L}\d]/gu, '');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question