mathiasbynens / emoji-regex

A regular expression to match all Emoji-only symbols as per the Unicode Standard.
https://mths.be/emoji-regex
MIT License
1.74k stars 174 forks source link

Why does the second result return false? #112

Closed mqliutie closed 5 months ago

mqliutie commented 5 months ago
const emojiRegex = require('emoji-regex')
const reg = emojiRegex();
console.log(reg.test('\ud83d\ude02'))
// output : true
console.log(reg.test('\ud83d\ude02'))
// output: false
mathiasbynens commented 5 months ago

From the README:

const emojiRegex = require('emoji-regex');
// Note: because the regular expression has the global flag set, this module
// exports a function that returns the regex rather than exporting the regular
// expression itself, to make it impossible to (accidentally) mutate the
// original regular expression.

See https://2ality.com/2013/08/regexp-g.html#flag-g-problem for more details on this problem.

mqliutie commented 5 months ago

Sry~~~