title: VBS script to report AD groups - Regex pattern not working with multiple matches
body: <p>Having an issue with getting a regex statement to accept two expressions.</p>
  
  <p>The "re.pattern" code here works:</p>
  
  <pre><code>If UserChoice = "" Then WScript.Quit  'Detect Cancel
  re.Pattern = "[^(a-z)^(0,4,5,6,7,8,9)]"
  re.Global = True    
  re.IgnoreCase = True
  if re.test( UserChoice ) then 
     Exit Do
   End if
   MsgBox "Please choose either 1, 2 or 3 ", 48, "Invalid Entry"
  </code></pre>
  
  <p>While the below "regex.pattern " code does not. I want to use it to format the results of a DSQUERY command where groups are collected, but I don't want any of the info after the ",", nor do i want the leading CN= that is normally collected when the following dsquery is run:
  <strong>"dsquery.exe user forestroot -samid "&amp; strInput &amp;" | dsget user -memberof")</strong></p>
  
  <p>The string I want to format would look something like this before formatting:</p>
  
  <p>CN=APP_GROUP_123,OU=Global Groups,OU=Accounts,DC=corp,DC=contoso,DC=biz</p>
  
  <p>This is the result I want:</p>
  
  <p>APP_GROUP_123</p>
  
  <pre><code>Set regEx = New RegExp
  **regEx.Pattern = "[,.*]["CN=]"**
  Result = regEx.Replace(StrLine, "")
  </code></pre>
  
  <p>I'm only able to get the regex to work when used individually, either </p>
  
  <pre><code>   regEx.Pattern = ",."
  </code></pre>
  
  <p>or</p>
  
  <pre><code>regEx.Pattern = "CN="
  </code></pre>
  
  <p>code is nested here:</p>
  
  <pre><code>Set InputFile = FSO.OpenTextFile("Temp.txt", 1)
  Set InputFile = FSO.OpenTextFile("Temp.txt", 1)
  set OutPutFile = FSO.OpenTextFile(StrInput &amp; "-Results.txt", 8, True)
  
  do While InputFile.AtEndOfStream = False
      StrLine = InputFile.ReadLine
        If inStr(strLine, TaskChoice) then    
       Set regEx = New RegExp
       regEx.Pattern = "[A-Za-z]{2}=(.+?),.*"
       Result = regEx.Replace(StrLine, "")
       OutputFile.write(Replace(Result,"""","")) &amp; vbCrLf
        End if
  </code></pre>