Noam Hacker Noam Hacker - 1 year ago 54
Javascript Question

Javascript/dingbats: counting the number of ✔'s in a string

I am trying to count the checkmarks in a given string. my string may be:

var myString = "one ✔ two ✔ three ✔"

I have tried using
myString.match(/✔/g) || []).length;
, but this is returning
(I believe that happens because ✔ is a dingbat symbol).

I know the unicode for "✔" is 2714, can I use this in my expression?

Answer Source

I have solved my problem: I used the "unicode escape sequence" \u with the 2714 unicode:

.match(/\u2714/g) || []).length;

The problem was likely due to a character encoding issue (see the comments on my question), but this solution seems to be a safe choice.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download