I've been working on a weekend project, a simple, lightweight XML parser, just for fun, to learn more about Regexes. I've been able to get data in atributes and elements, but am having a hard time separating tags. This is what I have:
    CharSequence inputStr = "<a>test</a>abc<b1>test2</b1>abc1";
    String patternStr = openTag+"(.*?)"+closeTag;
    Pattern pattern = Pattern.compile(patternStr);
    Matcher matcher = pattern.matcher(inputStr);
    StringBuffer buf = new StringBuffer();
    boolean found = false;
    while ((found = matcher.find())) {
      String replaceStr = matcher.group();
      matcher.appendReplacement(buf, "found tag (" + replaceStr + ")");
    }
    matcher.appendTail(buf);
    String result = buf.toString();
    System.out.println(result);
Output: found tag (<a>test</a>abc<b1>test2</b1>)abc1
I need to to end the 'found tag' at each tag, not the whole group. Any way I can have it do that? Thanks.
 
    