title: Remove pattern from string in Java
body: <p>I am currently working on a tool, which helps me to analyze a constantly growing <code>String</code>, that can look like this: <code>String s = "AAAAAAABBCCCDDABQ"</code>. What I want to do is to find a sequence of A's and B's, do something and then remove that sequence from the original <code>String</code>. </p>
  
  <p>My code looks like this:</p>
  
  <pre><code>while (someBoolean){
  
      if(Pattern.matches("A+B+", s)) {
          //Do stuff
          //Remove the found pattern
      }
  
      if(Pattern.matches("C+D+", s)) {
          //Do other stuff
          //Remove the found pattern
      }
  
  }
  return s;
  </code></pre>
  
  <p>Also, how I could remove the three sequences, so that <code>s</code> just contains <code>"Q"</code> at the end of the calculation, without and endless loop? </p>