Home > OS >  Why telegram emoji numbers are not deleted when removing special characters
Why telegram emoji numbers are not deleted when removing special characters

Time:10-22

I have a telegram bot and I want to remove all special characters and just returns numbers and A-Z,but the problem is that my regex pattern can remove any emojies except numbers like this :1️⃣2️⃣3️⃣4️⃣5️⃣6️⃣

I want to delete emoji numbers too

So this is my pattern :

text = '1️⃣Hi =) 1.This regex removes 2️⃣all special 6️⃣characters like this !@$#%^&*()_ =~`/\><.⚠️4️⃣'

text.toUpperCase().match(/[a-z] |\d (?:\.\d )?/gi)
    .map((m) => (isNaN(m) ? m :  m))

//Current output : 
// [1,'HI',1,'THIS','REGEX','REMOVES',2,'ALL', 'SPECIAL',6,'CHARACTERS', 'LIKE','THIS']


//What I want : 
// ['HI',1,'THIS','REGEX','REMOVES','ALL', 'SPECIAL','CHARACTERS', 'LIKE','THIS']

Also I don't know why it removed the last number emoji from string! (4️⃣)

CodePudding user response:

These numbers are emojis. To remove them, too, use the following:

text = '1️⃣Hi =) 1.This regex removes 2️⃣all special 6️⃣characters like this !@$#%^&*()_ =~`/\><.⚠️4️⃣'

console.log(
  text.toUpperCase().match(/[a-z] |(?!\d\uFE0F\u20E3)\d (?:\.\d )?/gi)
    .map((m) => (isNaN(m) ? m :  m))
)
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

The (?!\d\uFE0F\u20E3) negative lookahead will fail any match of \d (?:\.\d )? when the first digit is a part of the numeric emojis.

  • Related