I have a list of words and I have to output the number of words with no vowels in them. I have this so far
String matchString = "[^aeiou]"
for(String s: list) if(s.matches(matchString.toLowerCase())) {
System.out.println(s);
numMatches++;
}
I'm more worried that the reg expression is wrong.
Change regex to
[^aeiou]+
^-- important part
to test if string is build from one or more non vowel characters. Currently you are just checking if stirng is build from one character which is not a e i o u.
You can also make your regex case insensitive by adding (?i) flag at start. This way characters used in regex will represent its lower and upper case
(?i)[^aeiou]+
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With