๐emoji
๐ง under construction
/[^\p{L}\p{P}\s\p{N}\p{Sc}\p{Sm}]/g
codepen โฉ regex: emoji
const {log} = console;
let input = `
๐๐ฝ ๐๐ฝ ๐ค๐ฝ ๐ช๐ฝ ๐๐ฝ โ๐ฝ ๐คณ๐ฝ ๐
๐ฝ ๐๐ฝ ๐๐ฝ้ไบๆฏไธญๆๅญ๏ผthis is english.
ไธปไบบ๏ผๆๅคฉๆ2ไปถไบ๏ผ
๐ณ Google One ๆ่ฒป (US$2)ใ๐Paper Pro ($190/ๅๅนด)๏ผๅ ฑๅๅฎ็ขใ
10/5 ~ 10/18 ไบ็ด่ญฆๆใ
10/10 ~ 11/11 ้ๅๅๆ
ถใ
`;
const dateRange = /(\d{1,2})\/(\d{1,2})\s*([~-])\s*(\d{1,2})\/(\d{1,2})/g;
const usd = /us\$(\d+)/gi;
const fee = /\$?(\d+)\/([^\w\s),]+)/gu;
/*
- L : Letters
- P : Punctuation
- N : Number
- Sc: Symbol (currency) - "$"
- Sm: Symbol (math) - "~"
- Pc: Punctuation (connector) - underscore '_' and similar characters,
- Po: Punctuation (others) - ?
*/
// โญ๏ธ ้ๅไผผไนๅฏไปฅ็จไพๆพ emoji
const emojis = /[^\p{L}\p{P}\s\p{N}\p{Sc}\p{Sm}]/gu; // โญ๏ธ "/u" flag
// ---------- test run ----------
let result = input
.replace(emojis, '')
.replace(/[ ]+/g, ' ')
// 10/5 ~ 10/18 -> 10 ๆ 5 ๆฅๅฐ 10 ๆ 18 ๆฅ
.replace(dateRange, "$1 ๆ $2 ๆฅๅฐ $4 ๆ $5 ๆฅ")
.replace(usd, "$1 ็พๅ
") // US$345 -> 345 ็พๅ
.replace(fee, "ๆฏ$2 $1 ๅ
"); // 190/ๅๅนด -> ๆฏๅๅนด 190 ๅ
[
result,
// input.replace(fee, 'ๆฏ$2 $1 ๅ
'),
].forEach(x => log(x));
Last updated