我是java的新手并使用正则表达式。该方法似乎没问题,并且它在主题字符串上找到结果,但是当我尝试使用.group()获取实际字符串时,它是空的。这是代码:
public String TestRegularExpression(){
try{
Pattern regex = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
Matcher regexMatcher = regex.matcher(sourceCode);
while (regexMatcher.find()) {
results += "<li>" + regexMatcher.group() + "</li>";
matches ++;
}
} catch (PatternSyntaxException ex) {
results = "<li><strong class='ibm-important'>Syntax error in the regular expression</strong></li>";
}
if(results == null){results = "<li><strong class='ibm-important'>No meta tags found</strong></li>";}
return "<h3>" + h3Title + " (" + matches + " found)</h3><ul>" + results + "</ul>";
}
任何帮助将不胜感激!!!
答案 0 :(得分:1)
难道你只是没有看到输出?如果直接将匹配输出到HTML而不引用它,那么只需在HTML代码中插入META标记,Web浏览器就不会呈现它。