java - 在java中搜索文件中的多个字符串

标签 java

String[] searchText = {"体育","足球","比赛","时间"}; 我如何搜索这些词是否在文件中可用

最佳答案

这应该可以工作(给定一些代表文档的 String )

Pattern p = Pattern.compile("(sports|football|play|time)");
Matcher m = p.matcher(s);

int start = 0;
while (m.find(start)) {
    System.out.println("Match found: " + m.group(1) + " at position: " + m.start());
    start = m.end();
}

关于java - 在java中搜索文件中的多个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5694913/

相关文章:

java - Kotlin (Mutable)List<(raw) kotlin.Any?> 转换为 List<JsonObject>

java - 运行时出现 ClassNotFoundException 但应用程序编译

java - 按钮和 Action 监听器的网格

设置 "user.dir"时 Java : File. exists() 不一致

java - : '#i' when parsing c grammar 处的 token 识别错误

java - Android应用程序执行时强制关闭

java - Java 线程名称是如何选择的?

java - 如何通过maven编译classes排除注解

java - Jolokia 防止 Tomcat 关闭

java - @事务: Not committing at end of transaction; using Spring Boot and neo4j