title: Qt - how to define regular expression in QString
body: <p>I've <a href="https://stackoverflow.com/questions/31557088/qt-capture-digit-inside-tag">worked</a> on regular expression on Qt , I want to replace all sub string with specific regular expression with image.</p>
  
  <p>my tag struct is combination of <code>&lt;</code> , <code>sml</code> , <code>digits (one or two)</code> and <code>/&gt;</code> and my QString is <code>draftMsg</code>. It will work if I use regular expression once.</p>
  
  <p>for example : "<em>hello <code>&lt;sml7/&gt;</code></em>" will be change to hello and photo with label 7 in my directory.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>           QRegExp rxlen("&lt;sml(\\d{1,2})/&gt;");
             if (draftMsg.contains(rxlen))
             {
                  QString str = rxlen.capturedTexts()[1];
                  int index = str.toInt();
                  smileyClicked(index-1);
  
                  m_messageEdit-&gt;insertHtml(QString("&lt;img src=\":images/smiley/%1_64.png\" width=%2 /&gt;")
                                            .arg(index, 2, 10, QLatin1Char('0')).arg(smileyWidth));
  
                  draftMsg = draftMsg.remove(rxlen);
             } 
  </code></pre>
  
  <p>Actually it replace wrongly when I write string like : "<em>hello <code>&lt;sml7/&gt;&lt;sml1/&gt;</code></em>". It will replace both tag to image with label 7.</p>
  
  <p>I searched and I found <a href="http://apiexamples.com/cpp/QtCore/QRegExp.html#L3" rel="nofollow noreferrer">it</a>. I trying to use captureCount() to keep Regular expression's number and use it.</p>
  
  <p>I've created this function:</p>
  
  <pre><code>void MessageDialog::regInMessage(QString pattern, QString string)
  {
      QRegExp regex(pattern);
      if (regex.indexIn(string) &lt; 0) {
          qDebug("Can't find a match.");
          return;
      }
      qDebug() &lt;&lt; regex.captureCount();
  }
  </code></pre>
  
  <p>But it gives me "1" instead of two.</p>
  
  <p>Any suggestion to count regular expression on my QString?</p>