title: REGEX to Capture All Words Between Two Strings
body: <p>Using VBScript or VBA I'm trying to write a REGEX Query to capture all Words between two specific string values.</p>
  
  <p>Conditions:
  Multiline, Global</p>
  
  <p>I'm trying to capture all words between the 'Logs:' and 'WORKSTATION#' Strings</p>
  
  <p>Test String:</p>
  
  <pre><code>show access-log log brief
  Logs:
  main
  streaming
  ssl
  cifs
  mapi
  im
  p2p
  WORKSTATION#(config)show
  </code></pre>
  
  <p>Expected Result:</p>
  
  <pre><code>main, streaming, ssl, cifs, mapi, im, p2p
  </code></pre>
  
  <p>My current non-working code:</p>
  
  <pre><code>Function GetLogList()
  Dim strInput, objRegEx, oRegResults
  Dim X, Y, Z
  
  strInput = "show access-log log brief" &amp; vbCrLf &amp; _
  "Logs:" &amp; vbCrLf &amp; _
  "main" &amp; vbCrLf &amp; _
  "streaming" &amp; vbCrLf &amp; _
  "ssl" &amp; vbCrLf &amp; _
  "cifs" &amp; vbCrLf &amp; _
  "mapi" &amp; vbCrLf &amp; _
  "im" &amp; vbCrLf &amp; _
  "p2p" &amp; vbCrLf &amp; _
  "WORKSTATION#(config)show"
  
  Set objRegEx = CreateObject("VBScript.RegExp")
  objRegEx.IgnoreCase = True
  objRegEx.MultiLine = True
  objRegEx.Global = True
    'Need Help with pattern
  objRegEx.Pattern = ":\s*(\S*)\s*?WORKSTATION#"
  Set oRegResults = objRegEx.Execute(strInput)
  For X = 0 To oRegResults.Count - 1
      Debug.Print oRegResults(X).Value
      For Y = 0 To oRegResults(X).SubMatches.Count - 1
          If oRegResults(X).SubMatches(Y) &lt;&gt; vbNullString Then
              Debug.Print oRegResults(X).SubMatches(Y)
          End If
      Next
  Next
  
  End Function
  </code></pre>
  
  <p>I would greatly appreciate any help with my REGEX pattern to capture all words between the : and WORKSTATION#.  Thank You!</p>
  
  <p>EDIT:</p>
  
  <p>Thanks for the suggestions.  I had a laps and didn't think of this.  I had thought my actual strings would have additional whitespace but it turns out the below works great capturing the whole string and splitting by vbCrLf.  Thank You to everyone who helped.</p>
  
  <p>Final Routine:</p>
  
  <pre><code>Function GetLogListArray(strInput)
  Dim objRegEx, oRegResults
  GetLogListArray = vbNullString
  Set objRegEx = CreateObject("VBScript.RegExp")
  objRegEx.IgnoreCase = True
  objRegEx.MultiLine = True
  objRegEx.Global = True
  objRegEx.Pattern = "Logs\:\s*([\S\s]*?)\s*?\S*?#"
  Set oRegResults = objRegEx.Execute(strInput)
  If oRegResults.Count = 0 Then Exit Function
  If oRegResults(0).Submatches.Count = 0 Then Exit Function
  GetLogListArray = Split(oRegResults(0).Submatches(0), vbCrLf)
  End Function
  </code></pre>