title: Regex - Get String Between / Get All Strings Betwen?
body: <p>I can only seem to find help for PHP on this subject so am opening a new question!</p>
  
  <p>I have written a function to get a string between 2 other strings but at the moment it is still returning the first part of the string and simply removing anything after the EndSearch value:</p>
  
  <pre><code>Public Function GetStringBetween(ByVal Haystack As String, ByVal StartSearch As String, ByVal EndSearch As String) As String
      If InStr(Haystack, StartSearch) &lt; 1 Then Return False
      Dim rx As New Regex("(?=" &amp; StartSearch &amp; ").+(?=" &amp; EndSearch &amp; ")")
      Return (rx.Match(Haystack).Value)
  End Function
  </code></pre>
  
  <p>Demo Usage:</p>
  
  <pre><code>Dim Haystack As String = "hello find me world"
      Dim StartSearch As String = "hello"
      Dim EndSearch As String = "world"
      Dim Content As String = GetStringBetween(Haystack, StartSearch, EndSearch)
      MessageBox.Show(Content)
  </code></pre>
  
  <p>Returns: hello find me</p>
  
  <p>Also, in PHP I have the following function:</p>
  
  <pre><code>function get_all_strings_between($string, $start, $end){
  preg_match_all( "/$start(.*)$end/U", $string, $match );
  return $match[1];
  }
  </code></pre>
  
  <p>Is there a similar function in VB.NET for preg_match_all?</p>
  
  <p>Example Function (Non-Functional Due To Returning m.Groups):</p>
  
  <pre><code>Public Function GetStringBetween(ByVal Haystack As String, ByVal StartSearch As String, ByVal EndSearch As String, Optional ByVal Multiple As Boolean = False) As String
          Dim rx As New Regex(StartSearch &amp; "(.+?)" &amp; EndSearch)
          Dim m As Match = rx.Match(Haystack)
          If m.Success Then
              If Multiple = True Then
                  Return m.Groups
              Else
                  Return m.Groups(1).ToString()
              End If
          Else
              Return False
          End If
      End Function
  </code></pre>