Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tried string.replace(/\u10000-\u10FFFF/g, ''), but sadly \u doesn't support 10000+

like image 427
Brian Cray Avatar asked Feb 17 '23 15:02

Brian Cray


1 Answers

To specify code points beyond U+FFFF, you need to look for UTF-16 surrogate pairs:

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

For future reference: One of the current ECMAScript proposals is to add a /u flag to support Unicode supplementary characters, which would allow:

string.replace(/[\u{10000}-\u{10ffff}]/gu, '')
like image 159
Jonathan Lonowski Avatar answered Mar 03 '23 15:03

Jonathan Lonowski