Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>What ever you are trying to achieve, this will help you:</p> <p>To count only Hiragana+Katakana+Kanji (Japanese) Chars (excluding punctuation marks):</p> <pre><code>var x = "これは猫です、けどKittyも大丈夫。"; x.match(/[ぁ-ゖァ-ヺー一-龯々]/g).length; //Result: 12 : これは猫ですけども大丈夫 </code></pre> <p><strong>Updated:</strong> </p> <p>To count only words in Alphabet:</p> <pre><code>x.match(/\w+/g).length; //Result: 1 : "Kitty" </code></pre> <p>All in one line (as function):</p> <pre><code>function myCount(str) { return str.match(/[ぁ-ゖァ-ヺー一-龯々]|\w+/g).length; } alert(myCount("これは猫です、けどKittyも大丈夫。")); //13 alert(myCount("これは犬です。DogとPuppyもOKですね!")); //14 </code></pre> <p>These are the arrays resulted of match:</p> <pre><code>["こ", "れ", "は", "猫", "で", "す", "け", "ど", "Kitty", "も", "大", "丈", "夫"] ["こ", "れ", "は", "犬", "で", "す", "Dog", "と", "Puppy", "も", "OK", "で", "す", "ね"] </code></pre> <p><strong>Updated (JAP, KOR, CH):</strong></p> <pre><code>function myCount(str) { return str.match(/[ぁ-ㆌㇰ-䶵一-鿃々가-힣-豈ヲ-ン]|\w+/g).length; } </code></pre> <p>These will cover around 99% of the Japanese, Chinese and Korean. You may need to manually add extra characters that are not included such as "〶".</p> <p>A very good reference is:</p> <p><a href="http://www.tamasoft.co.jp/en/general-info/unicode.html" rel="nofollow">http://www.tamasoft.co.jp/en/general-info/unicode.html</a></p> <p>This should solve your question.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload