以下是Java代码示例:

String str = "hello world";
int count = 0;
Pattern pattern = Pattern.compile("o");
Matcher matcher = pattern.matcher(str);
while (matcher.find()) {
    count++;
}
System.out.println("o出现的次数为:" + count);

输出结果为:

o出现的次数为:2
java使用正则表达式查找hello world中o出现的次数

原文地址: https://www.cveoy.top/t/topic/ex27 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录