Home > Enterprise >  Why are the unicode numbers not being selected in regex
Why are the unicode numbers not being selected in regex

Time:05-09

I am creating a discord command to create a poll but for whatever reason, the emoji 1️⃣ wont pick up.

MY CODE

const EMOJIREGEX = /((?<!\\)<:[^:] :(\d )>)|\p{Emoji_Presentation}|\p{Extended_Pictographic}/gmu;



  let element='1️⃣some text➡️'
        if (element.match(EMOJIREGEX)) {
          let emojis = element.match(EMOJIREGEX)
          console.log(emojis)
        
        } else {
        console.log('no emojis')
         
        }

OUTPUT

[ '➡' ]

I've tried several other emojis and the 0-9 ones are the only ones that wont work (which is unfortunate because they're prolly the most important ones)

Any help would be great, thanks!

CodePudding user response:

Use Emoji instead of Emoji_Presentation

const EMOJIREGEX = /((?<!\\)<:[^:] :(\d )>)|\p{Emoji}|\p{Extended_Pictographic}/gmu;

let element='1️⃣some text➡️'
let emojis = element.match(EMOJIREGEX);
if (emojis) {
  console.log(emojis)

} else {
console.log('no emojis')

}

List of aliases could be used: https://www.unicode.org/Public/UCD/latest/ucd/PropertyValueAliases.txt

  • Related