Closed roderickhsiao closed 7 years ago
Hi Mathias,
We are currently having a use case that will run through array to check if the item is emoji
const emojiRegex = require('emoji-regex'); const textList = ['😁', '😂', '😃' ,'😄', '😅', '😆']; const isEmoji = char => emojiRegex().text(char); textList.forEach(char => every(isEmoji(char));
The global search state needs to be reset so we will need to call emojiRegex every time instead of just create once like.
emojiRegex
const emojiRegex = require('emoji-regex'); const REGEX = emojiRegex(); const textList = ['😁', '😂', '😃' ,'😄', '😅', '😆']; const isEmoji = char => REGEX.text(char); textList.forEach(char => every(isEmoji(char));
probably really minor but there do have some perf difference if the use case is just to match single string.
https://jsperf.com/create-regex/1
Would like to hear about your idea and suggestion.
Thanks and Cheers!
Have you tried resetting lastIndex before using the regex?
lastIndex
const isEmoji = (char) => { REGEX.lastIndex = 0; return REGEX.text(char); };
good call ;) Didn't think about it.
Thanks greatly
Hi Mathias,
We are currently having a use case that will run through array to check if the item is emoji
The global search state needs to be reset so we will need to call
emojiRegex
every time instead of just create once like.probably really minor but there do have some perf difference if the use case is just to match single string.
https://jsperf.com/create-regex/1
Would like to hear about your idea and suggestion.
Thanks and Cheers!