Skip to content

Instantly share code, notes, and snippets.

@RhinoLu
Last active October 14, 2015 11:20
Show Gist options
  • Save RhinoLu/9630d28f240a847b6aba to your computer and use it in GitHub Desktop.
Save RhinoLu/9630d28f240a847b6aba to your computer and use it in GitHub Desktop.
判斷字串中有幾個中文字 check how many chinese words in a string
var str = "test 測試";
var chineseCount = str.split(/[\u4e00-\u9fa5]/).length - 1;
console.log(chineseCount);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment