Strip U + 10000-U + 10FFFF from javascript strings

Tried string.replace(/\u10000-\u10FFFF/g, '') , but unfortunately \u does not support 10000 +

+4
source share
1 answer

To specify code points outside of U + FFFF, you need to look for pairs of UTF-16 surrogates :

 string.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g, '') 

For future reference: one of the current ECMAScript proposals is to add the /u flag to support Additional Unicode characters that will allow:

 string.replace(/[\u{10000}-\u{10ffff}]/gu, '') 
+8
source

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


All Articles