function countWords(text) {
    return (text+=".").replace(/(\,|\.|:|;|\!|\?|\s)+/g, " ").split(" ").length - 1;
}

countWords(`I am Jiyu; Jiyu means "Freedom" or "Liberty" in Japanese.`); // 10
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account log in.