Brian Cray
Brian Cray

Reputation: 1275

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

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

Upvotes: 4

Views: 1581

Answers (1)

Jonathan Lonowski
Jonathan Lonowski

Reputation: 123513

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, '')

Upvotes: 8

Related Questions