How to use regular expression In Javascript
In this method, we will create a regular expression for the vowels and test if the given input char satisfy the regex condition.
Example: In this example, we will implement regex for the vowels and output the result.
function checkChar(char){
ch = char.toLowerCase();
const regex = /^[aeiou]$/i;
if(regex.test(ch))
return console.log("Given character is a Vowel");
return console.log("Given character is a Consonent");
}
checkChar('I');
checkChar('Z');
Output
Given character is a Vowel Given character is a Consonent
JavaScript Program to Find if a Character is a Vowel or Consonant
In this article, we will see different approaches to finding whether a character is a vowel or a consonant using JavaScript. We will check the condition of a character being Vowel and display the result.