3 Replies Latest reply on Mar 11, 2012 8:18 AM by john_dube

    VBScript regex in Linux?


      I'm trying to write a cross-platform script that uses the regex object type.  This is easy in Windows vbscripts:


      Dim myregex

      Set myregex = New Regexp


      However, the same code does not work in Linux.  How do I create and use regular expressions in VBScript in Linux?

        • 1. Re: VBScript regex in Linux?



          Regular expressions in VBScript work on Linux - could you provide additional details on the script host you are using, and specific error messages?


          There is one particular feature related to regular expressions that is missing on Linux, RegExp.SubMatches.


          The SubMatches property was first available in VBScript version 5.5, the version of VBScript included with Expedition Enterprise is 5.1.


          Instead of using SubMatches, you can use the Replace method to extract a particular submatch from the matching string.


          For example, if you have a regular expression to parse an email address, you can use the Replace function to get each captured substring:


               Dim sInputString : sInputString = "fred@acme.com"

               Dim re : Set re = New Regexp

               re.Pattern = "(\w+)@(\w+)\.com"

               Dim Matches : Set Matches = re.Execute(sInputString)

               If Matches.Count > 0 Then

                    Dim sUsername : sUsername = re.Replace(sInputString, "$1")

                    Dim sCompany : sCompany = re.Replace(sInputString, "$2")

                    MsgBox "Username is " & sUsername & ", Company is " & sCompany

               End If



          • 2. Re: VBScript regex in Linux?

            Ah, that was just enough to get me started looking in the right direction.  I'm including an INI file reader that I found on the net in VBScript from




            and using the "Include" functions from this site.  For some reason, every time an object is not properly used (like trying to call Submatches), DxDesigner in Linux silently fails but continues execution without reporting an error.  Any idea why?



            • 3. Re: VBScript regex in Linux?

              Error reporting is severely diminished when you use the Include function.  Also, if you have disabled error handling (On Error Resume Next) in either the parent or child script, you would not see the error reported at all.


              I recommend that you completely debug in a standalone mode, before reusing code.  I find using VBScript classes helpful, then I have a few lines of code at the bottom of the script that I comment out before reusing that code in another script.