Skip to content

Instantly share code, notes, and snippets.

@MaxXxiMast
Last active June 1, 2017 19:06
Show Gist options
  • Save MaxXxiMast/7299eedaf13f4c229ccf9606d8331742 to your computer and use it in GitHub Desktop.
Save MaxXxiMast/7299eedaf13f4c229ccf9606d8331742 to your computer and use it in GitHub Desktop.
Check the number of vowels in a string
function countVowels(str){
return (str.match(/[aeiou]/gi) == null) ? 0 : str.match(/[aeiou]/gi).length;
}
// return (str.match(/[aeiou]/gi) || []).length; - shorter version
// [aeiou] can be replaced by any other regex as per requirement
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment