title: How to replace any occurrence of a word between quotes
body: <p>I need to be able to replace all occurrences of the word "and" ONLY when it occurs between single quotes.  For example replacing "and" with "XXX" in the string: </p>
  
  <p><code>This and that 'with you and me and others' and not 'her and him'</code></p>
  
  <p>Results in:  </p>
  
  <p><code>This and that 'with you XXX me XXX others' and not 'her XXX him'</code></p>
  
  <p>I have been able to come up with regular expressions which nearly gets every case, but I'm failing with the "and" between the two sets of quoted text.</p>
  
  <p>My code:</p>
  
  <pre><code>String str = "This and that 'with you and me and others' and not 'her and him'";
  
  String patternStr = ".*?\\'.*?(?i:and).*?\\'.*";
  Pattern pattern= Pattern.compile(patternStr);
  Matcher matcher = pattern.matcher(str);
  System.out.println(matcher.matches());
  while(matcher.matches()) {
      System.out.println("in matcher");
      str = str.replaceAll("(?:\\')(.*?)(?i:and)(.*?)(?:\\')", "'$1XXX$2'");
      matcher = pattern.matcher(str);
  }
  
  System.out.println(str);
  </code></pre>