开发者

Regular expression not returning the .group() value

I'm new with java and using regular expressions. The method seems to be OK, and it's finding results on the subject string, but when I try to get the actual string using .group(), it's empty. here's the code:

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

Any help will be much appre开发者_开发技巧ciated!!!


Couldn't it be that you're just not seeing the output? If you output the match directly to HTML without quoting it, that'll just insert the META tag in the HTML code, and the web browser won't render it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜