title: How do you return the 2nd through nth match of a vbscript regex capturing group
body: <p>I have a regular expression that matches a particular text string and then is supposed to return the matches in cells adjacent to the matched string. I'm using a capturing group so there could be more than one match. I'm able to return the first match without any problems, but I can't figure out how to return the second through nth matches. </p>
  
  <p>My code follow:</p>
  
  <pre><code>Sub splitUpComments()
      Dim regEx As New RegExp
      Dim strPattern As String
      Dim strInput As String
      Dim strReplace As String
      Dim Myrange As Range
  
      Set Myrange = ActiveSheet.Range("G2:G5")
  
      For Each c In Myrange
          strPattern = "(\S.+?[.?!])(?=\s+|$)"
          If strPattern &lt;&gt; "" Then
              strInput = c.Value
              strReplace = "$1"
  
              With regEx
                  .Global = True
                  .MultiLine = True
                  .IgnoreCase = False
                  .Pattern = strPattern
              End With
  
              If regEx.test(strInput) Then
                  c.Offset(0, 1) = regEx.Replace(strInput, "$1")
                  c.Offset(0, 2) = regEx.Replace(strInput, "$2")
                  c.Offset(0, 3) = regEx.Replace(strInput, "$3")
              Else
                  'do nothing
              End If
          End If
      Next
  End Sub
  </code></pre>
  
  <p>Given the following Target String:  </p>
  
  <pre><code>"This is a test one.  This is a test two.  This is a test three."
  </code></pre>
  
  <p>I was hoping to see:</p>
  
  <ul>
  <li>This is a test one.   This is a test two.     This is a test three.</li>
  </ul>
  
  <p>You can see the regular expression working here at Regex 101:  <a href="http://regex101.com/r/wU0oW9/1" rel="nofollow">Working Regular Expression</a></p>
  
  <p>but instead I'm getting:</p>
  
  <pre><code>This is a test one. This is a test two. This is a test three.       $2$2$2      $3$3$3
  </code></pre>
  
  <p>(Where the first cell contains the whole target string and the next two columns contain $2$2$2 and $3$3$3, respectively.) </p>
  
  <p>It look as though (1) the regular expression is not working and (2) that $2 and $3 represent the 2nd and third capture groups, not the 2nd and 3rd instance of the first capture group. Can anyone shed any light on this.  Thanks.</p>