Found lots of questions about "How to GET the last occurrence of a string" but none about "how to DON'T get it", and this is my problem.
I'm working with emojis and I want to count each emoji (<img>
) of the string as one char, so I can get the right length of the string.
When replacing, it finds the beginning (<img
), but the last part (>
) is being caught at the last occurrence, not the first one, which closes the first <img
tag.
This is my code (without unnecessary stuff):
var typed = $(this).html();
var matches = typed.match(/\<img.*:"\>/g);
if (matches != null) {
for (var i = 0; i < matches.length; i++) {
console.log('Match ' + i + ': ' + matches[i]);
}
}
The log result is this:
Match 0: <img src="/platform/resources/plugins/emoji-area/img/joy.png" class="img" alt=":joy:"><img src="/platform/resources/plugins/emoji-area/img/evil.gif" class="img" alt=":evil:"><img src="/platform/resources/plugins/emoji-area/img/evil.gif" class="img" alt=":evil:">
But it should be:
Match 0: <img src="/platform/resources/plugins/emoji-area/img/joy.png" class="img" alt=":joy:">
Match 1: <img src="/platform/resources/plugins/emoji-area/img/evil.gif" class="img" alt=":evil:">
Match 2: <img src="/platform/resources/plugins/emoji-area/img/evil.gif" class="img" alt=":evil:">
How do I fix it to get each <img>
separated?