title: SpannableStringBuilder replace content with Regex
body: <p>I have the following code in which I am going to mark the contents between the curly braces with <code>SpannableString</code> and remove the curly braces but it gives wrong result.</p>
  
  <pre><code>String text = "the {quic}k brown {fox} jumps {over} the lazy dog. {A Quick} {brow}nfoxjumpsoverthelazydog";
  
  tv.setText(makeSpannable(text, "\\{.*?\\}"));
  public SpannableStringBuilder makeSpannable(String text, String regex) {
      SpannableStringBuilder spannable = new SpannableStringBuilder(text);
      Pattern pattern = Pattern.compile(regex);
      Matcher matcher = pattern.matcher(spannable.toString());
      while (matcher.find()) {
          String word = matcher.group();
          String abbr = word.toString().substring(1, word.length() - 1);
          spannable.setSpan(new ForegroundColorSpan(Color.RED), matcher.start(), matcher.end(),  Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
          spannable.replace(matcher.start(), matcher.start() + abbr.length() , abbr);
      }
      return spannable;
  }
  </code></pre>
  
  <p>Input:</p>
  
  <pre><code>the {quic}k brown {fox} jumps {over} the lazy dog. {A Quick} {brow}nfoxjumpsoverthelazydog
  </code></pre>
  
  <p>Output:
  <a href="https://i.stack.imgur.com/1dZpj.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/1dZpj.jpg" alt="enter image description here"></a></p>