Java正则表达式-查找没有元音的字符串 [英] Java Regular expression - find strings with no vowels

查看:42
本文介绍了Java正则表达式-查找没有元音的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个单词列表,我必须输出其中没有元音的单词数量.到目前为止,我有这个

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++;
    }

我更担心reg表达式错误.

I'm more worried that the reg expression is wrong.

推荐答案

这个对我有用:

[^aeiou]+$

此外,您应该小写字符串,而不是表达式:

Also you should lowercase the string, not the expression:

if (s.toLowerCase().matches(matchString))

这篇关于Java正则表达式-查找没有元音的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆