title: regex: replace matched text with output of method it's passed to
body: <p>I have a text file that's marked up like this: </p>
  
  <pre><code>Old McDonald had a &lt;:farm/101:&gt;
  </code></pre>
  
  <p>When the program reading through this text file hits this tag, it passes <code>farm/101</code> to a method that converts the tag to appropriate HTML code, depending on what sort of tag is passed. In this case, the word farm needs to be turned into a hyperlink, with 101 as its HREF. This is done in the <code>parseTag()</code> method, which is called as follows: </p>
  
  <pre><code>Pattern pattern = Pattern.compile("&lt;:(.+?):&gt;");        
  Matcher tagMatch = pattern.matcher(in);
  
  while (tagMatch.find()) {
      String parsed = parseTag(tagMatch.group(1);
      // replace tagMatch.group(0) with parsed
  }
  </code></pre>
  
  <p>I then want to replace the entire tag with the output of that method. I've thought about doing something like: </p>
  
  <pre><code>Pattern pattern = Pattern.compile("&lt;:");    
  String split = pattern.split(in);    
  StringBuilder sb = new StringBuilder();
  for (int i = 0; i &lt; split.length; i++){
      if (i%2 == 0) sb.append(split[i]);
      else sb.append(parseTag(split[i]);
  } 
  String final = sb.toString();
  </code></pre>
  
  <p><code>final</code> here would give me what I want, but this seems messy..</p>