title: find multiple regex patterns using vbscript
body: <p>Sorry, but I am a bit new to RegEx and hope someone is able to help.</p>
  
  <p>Files in questions:</p>
  
  <pre><code>    Apples.A.Tasty.Treat.Author-JoeDirt.doc
      Cooking with Apples Publisher-Oscar Publishing.txt
      Candied.Treats.Author-JenBloc.Publisher-Event.docx
  </code></pre>
  
  <p>I currently use this piece of vbscript code to replace spaces or dashes in the filename with a period but I am wondering if there is a more efficient way to accomplish this?</p>
  
  <pre><code>    Set colRegExMatches = strRegEx.Execute(objSourceFile.Name)
      For Each objRegExMatch in colRegExMatches
        strResult = InStr(objSourceFile.Name, objRegExMatch)
        objTargetFile = Left(objSourceFile.Name, (strResult -1)) &amp; objRegExMatch.Value
        objTargetFile = Replace(objSourceFile.Name, " ", ".", 1, -1, 1)
        objTargetFile = Replace(objSourceFile.Name, "-", ".", 1, -1, 1)
        objSourceFile.Name = objTargetFile
      Next
  </code></pre>
  
  <p>Once the script above is complete, I have the following list of files:</p>
  
  <pre><code>    Apples.A.Tasty.Treat.Author-JoeDirt.doc
      Cooking.with.Apples.Publisher-Oscar.Publishing.txt
      Candied.Treats.Author-JenBloc.Publisher-Event.docx
  </code></pre>
  
  <p>Now, I want to find anything beginning with Author or Publisher and simply delete the text until the extension. </p>
  
  <pre><code>    myRegEx.Pattern = (?:Author|Publisher)+[\w-]+\.
  </code></pre>
  
  <p>This works mostly for the files with the exception if there is an additional period to add a second part of the publisher name or year of publication or book number.</p>
  
  <pre><code>    Apples.A.Tasty.Treat.doc
      Cooking.with.Apples.Publishing.txt
      Candied.Treats.docx
  </code></pre>
  
  <p>I tried this code and it seems to work but I have to specify the file extensions.</p>
  
  <pre><code>    myRegEx.Pattern = (?:Author|Publisher)[\w-](\S*\B[^txt|docx|doc][\w-].)
  </code></pre>
  
  <p>If I try the following, it strips the extension for the Candied.Treats file</p>
  
  <pre><code>    myRegEx.Pattern = (?:Author|Publisher)[\w-](\S*\B[^][\w-].)
  
      Apples.A.Tasty.Treat.doc
      Cooking.with.Apples.txt
      Candied.Treats.
  </code></pre>
  
  <p>I have been using the RegExr Builder at <a href="http://gskinner.com/RegExr" rel="nofollow">http://gskinner.com/RegExr</a> to test my patterns but am at a loss right now. Finally once my pattern is working as expected how do I use that in my vbscript? Do I simply add a new line as per below?</p>
  
  <pre><code>    objTargetFile = Replace(objSourceFile.Name, "(?:Author|Publisher)[\w-](\S*\B[^txt|docx|pdf|doc][\w-].)", "", 1, -1, 1)
  </code></pre>
  
  <p>Thanks.</p>
  
  <p>This is the new vbscript code which seems to do nothing.</p>
  
  <pre><code>    strFixChars = InputBox("Do you want to replace spaces, dashes and strip tags? (Y/N)", "Confirmation")
      Set strRegEx = new RegExp
      For Each objSourceFile in colSourceFiles
        strFileExt = objFSO.GetExtensionName(objSourceFile)
        objLogFile.WriteLine "Input File: " &amp; objSourceFile.Name
        strCount = Len(objSourceFile.Name)
        strRegEx.Pattern = "(?:Author|Publisher)(.+)\."
        strRegEx.IgnoreCase = True
        strRegEx.Global = True
        Set colRegExMatches = strRegEx.Execute(objSourceFile.Name)
        For Each objRegExMatch in colRegExMatches
          strResult = InStr(objSourceFile.Name, objRegExMatch)
          objTargetFile = Left(objSourceFile.Name, (strResult -1)) &amp; objRegExMatch.Value
              If strFixChars = "Y" Then
              objTargetFile = Replace(objSourceFile.Name, " ", ".")
              objTargetFile = Replace(objSourceFile.Name, "-", ".")
              objTargetFile = Replace(objSourceFile.Name, "(?:Author|Publisher)(.+)\.", "")
          End If
          objLogFile.WriteLine "Output File: " &amp; objTargetFile
          strFileList = strFileList &amp; vbCrlf &amp; objTargetFile
      Next
  Next
  </code></pre>