Js how Filter utf8 non-3-byte encoded string

how to js Filter utf8 non-3-byte encoded string

Mar.16,2021

conversion relationship table between Unicode and UTF-8 (the x character represents the bit occupied by the code point)

                Byte 1    Byte 2    Byte 3    Byte 4    Byte 5    Byte 6
  7    U+0000    U+007F    1    0xxxxxxx
11    U+0080    U+07FF    2    110xxxxx    10xxxxxx
16    U+0800    U+FFFF    3    1110xxxx    10xxxxxx    10xxxxxx
21    U+10000    U+1FFFFF    4    11110xxx    10xxxxxx    10xxxxxx    10xxxxxx
26    U+200000    U+3FFFFFF    5    111110xx    10xxxxxx    10xxxxxx    10xxxxxx    10xxxxxx
31    U+4000000    U+7FFFFFFF    6    1111110x    10xxxxxx    10xxxxxx    10xxxxxx    10xxxxxx    10xxxxxx

is either 3 bytes or

other than 0x0800-0xffff.
const str = '1\a';
const reg = /[^\u0800-\uffff]/g;
str.replace(reg,'');
Menu