title: regular expression replace two group
body: <p>I have pattern like : <code>&lt;[a-zA-Z][^&gt;]*(?:poster|src)=(['\"])([^'\"]+)\\1[^&gt;]*&gt;</code>
  here i want to replace the value of src or poster attributes.</p>
  
  <p>It is okey for</p>
  
  <pre><code>&lt;video src='srcVal' /&gt;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>&lt;video poster='posterVal' src='srcVal' /&gt;
  </code></pre>
  
  <p>but for</p>
  
  <pre><code>&lt;video poster='posterVal' src='srcVal' /&gt;
  </code></pre>
  
  <p>only changes src value, due to <code>matcher.group(2)</code> returning only <code>srcVal</code>.</p>
  
  <pre><code>public class Test {
      public static void main(String[] args) throws Exception {
          String html = "&lt;video poster='posterVal' src='srcVal' /&gt;";
          Pattern resourcePattern = Pattern.compile("&lt;[a-zA-Z][^&gt;]*(?:poster|src)=(['\"])([^'\"]+)\\1[^&gt;]*&gt;");
          Matcher matcher = resourcePattern.matcher(html);
          int last = 0;
          StringBuilder sb = new StringBuilder();
          while(matcher.find()) {
              String path = matcher.group(2) + "Changed";
              sb.append( html.substring(last, matcher.start(2)) + path );
              last = matcher.end(2);
          }
          sb.append(html.substring(last));
          System.out.println(sb);
          //outputs &lt;video poster='posterVal' src='srcValChanged' /&gt;
          //expecting &lt;video poster='posterValChanged' src='srcValChanged' /&gt;
      }
  }
  </code></pre>
  
  <p>Does any body has an idea how to do this?</p>