我一直在使用 Apache Tika 将 PDF 文件的内容提取到字符串中。但是,我需要在文件中搜索一些模式。
我相信我可能不得不使用正则表达式来搜索字符串。这是正确的方法和使用 Tika 检查 PDF 文件中是否存在特定关键字。
我正在使用以下代码,但它没有与正则表达式匹配。keyword
是我希望在我的文本中找到的字符串。
for (int i=0; i<num_keywords; i++) {
String keyword = keywords.get(i);
Pattern p = Pattern.compile(keyword);
Matcher m = p.matcher(handlerContent);
if(m.find())
{
System.out.println("Found comment: "+m.group());
}
//updatelog(keyword,f.getName());
}