7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

絵文字があるか判定する

Last updated at Posted at 2024-02-03

絵文字が含まれているかどうかを判別します。
入力された文章から絵文字を除去するコードはいくつか合ったけど、真偽で返すのは無かったので残します。
絵文字を判定しているサイトをいくつか比べたのですが、完璧に判定するのは難しいのですね...

const emoji = new RegExp(/[\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF]/, 'g');

const judgeEmoji = input => {
  return input.match(emoji) ? true : false
}

judgeEmoji('おはよー😇');   // true
judgeEmoji('こんに👨‍🍳ちは'); // true
judgeEmoji('こんばんは!'); // false

7
4
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?