Regular expression tester [Updated]

Change Page: 12 > | Showing page 1 of 2, messages 1 to 20 of 22
Author Message
mikeock

  • Total Posts : 124
  • Scores: 1
  • Reward points : 0
  • Joined: 6/8/2006
  • Status: offline
Regular expression tester [Updated] Thursday, June 29, 2006 7:44 AM (permalink)
0
At work i am limited to VBS due to the project.

I wrote this lil app for regular expressions through VBS.
A fellow employee did do a lil bit of fixing for the submatch and the global search.

Let me know what you think.
Original
 <html>
 <head>
  <title>Regex Tester</title>
 <HTA:APPLICATION
  icon = "c:\icons\hate.ico"
  Caption = "yes"
  Version = "1.1(a)"
 />
 <script language="VBScript">
 '#################### Start VBScript Section ####################
 'Sub to Run when Test RegEx button is pressed
 sub cmdTextBox
  dim string1, Re,s,colMatches,Test,ResultArr()
  
  'Configure Regular Expression
  set Re = new RegExp
  Re.Pattern = ExprStrin.TextBox.value
  
  ' Error if pattern is blank
  if Re.Pattern = "" then 
      DataAr1.InnerHTML = "<font color=red>Please enter a Regular Expression</font>"
      ClearSubs
  
  'Move on pattern is not blank
  else
      If ExprStrin.GlobalCheckBox.checked Then    'Set Global attribute according to checkbox
          Re.Global = true
      Else
          Re.Global = false
      End If
      
      If ExprStrin.caseCheckbox.checked Then    'Set IgnoreCase attribute according to checkbox
          Re.IgnoreCase = True
      Else
          Re.IgnoreCase = False
      End If
      s = ExprStrin.StringBox.value
      
      'Error if string to search is blank
      if s = "" then 
          DataAr1.InnerHTML = "<font color=red>Search String cannot be left blank</font>"
          ClearSubs
          
      ' Test regex if string is not blank
      else
      
          'If a match is found...
          if Re.Test(s) then 
              'Collect and Output Matches
              Set colMatches = Re.Execute(s)
              counter = 0
              numMatches = colMatches.count
              for each Test in colMatches
                  ReDim Preserve ResultArr(counter + 1)
                  ResultArr(counter) = Test.value
                  counter = counter + 1
              next
              dim tempstring
              for count2 = 0 to counter - 1
                  tempstring = tempstring & "<b>Match " & count2+1 & ": </b>" & ResultArr(count2) & "<br>"
              next
              DataAr1.InnerHTML = "<b>The following matches were found:</b><br>" & tempstring
              
              'Collect SubMatches and Store them in a String
              subMatchesString = ""
              For i=0 to numMatches-1    'Loop through each match
                  Set myMatch = colMatches(i)
                  numSubMatches = myMatch.submatches.count
                  If numSubMatches > 0 Then    'Loop through each submatch in current match
                      subMatchesString = subMatchesString & "<b>Submatches for Match " & i+1 & "</b><br>"
                      For j=0 to numSubMatches-1
                          subMatchesString = subMatchesString & myMatch.SubMatches(j) & "<br>"
                      Next
                  End If
              Next
              
              'Output submatches to correct field
              SubAr1.InnerHTML = subMatchesString
                  
          'If no match is found output error and sub strings
          else 
              DataAr1.InnerHTML = "No match was found for the regular expression."
              ClearSubs
          end if
      end if
  end if
  
  'Clear things up
  Set Re = Nothing
  Set colMatches = nothing
 end sub
 
 'Sub to Run when Clear Results button is pressed
 sub ClearDataAr1
  DataAr1.InnerHTML = ""
  ClearSubs
 end sub
 
 'Sub to clear submatches
 sub ClearSubs
  SubAr1.InnerHTML = ""
 End sub
 '#################### End VBScript Section ####################
 </script>
 </head>
 
 <body>
  <form action="some_form_handler.asp" method="post" id="ExprStrin" name="ExprStrin" target="_self">
      <table align="center">
          <tr>
              <td>Enter an expression</td>
              <td><input type="text" id="TextBox" name="TextEntry" value="" tabindex=1 size=66></td>
          </tr>
          <tr>
              <td>Enter a String</td>
              <td><textarea cols=50 rows=4 name="StringBox" tabindex=2></textarea>
              </td>
          </tr>
      </table>
      <table align="center" cellpadding=5>
          <tr>
              <td><input type=checkbox name="IgnoreCase" ID="CaseCheckBox" tabindex=-1>Ignore Case</td>
              <td><input type=checkbox name="Global" id="GlobalCheckBox" tabindex=-1>Global Search</td>
              <td><input type="button" value="Clear Results" onClick="ClearDataAr1" size=30 tabindex=3><td>
              <td><input type="button" value="Test RegEx" onClick="cmdTextBox" tabindex=4</td>
          </tr>
      </table>
 
      <table align="center">
          <tr>
              <td><br><font color=blue size=+1><b>Error or Result display</b></font></td>
          </tr>
      </table>
      <table align="center" frame="border" >
          <tr>
              <td><span id=DataAr1>Result will display here</span></td>
          </tr>
      </table>
      <table align="center" ID="Table1">
          <br>
          <tr><td><font color=blue size=+1><b>Substring Matches Display</b></font></td></tr>
      </table>
      <table align=center frame="border">
          <tr>
              <td><span id=SubAr1>Substrings will display here</span></td>
          </tr>
  
      </table>
  </form>
 </body>
 </html>
 


Edit: 2006/07/27
And now with all fixes. File loading, GUI enhancements.
App now features tool tips on almost all items.
Added a lot of coloring.
Cleaned out code where possible.
Try it and let me know
 <html>
 <head>
  <title>Regex Tester</title>
 <HTA:APPLICATION
  icon = "c:\icons\hate.ico"
  Caption = "yes"
  Version = "2.5"
 />
 <!-- Author : Mike D Adams [email=Mikeock01@hotmail.com]Mikeock01@hotmail.com[/email]
   Thanks to Jared Franklin for the submatches portion. 
   Thanks to all the suggestion and help from the users of the visualbasicscript.com forums
   2006/07/25
   -    Added tool-tips on text areas for exp and string
   -    Changed the color of all text areas to match the "theme" of the app
   2006/07/24 
   -     fixed some issues in the text processing portion (load/unload files)
   -    Added Tooltips for almost all buttons
   -    Disabled other file options once you have one selected
   -    Renamed close button to hide. Clarity sake
   -    Changed the file text to blue w\ a size of +1
   -    Added tooltips to the checkboxes
   -    Jumped version number to 2.5 (from 2.0)-->
 <script language="VBScript">
 '#################### Start VBScript Section ####################
 
 ''= refreshes the HTA page, which includes re-running any Windows_Onload code
 '' ============================================================================
 Sub reloadHTA()
   location.reload( True )
 End Sub
 
 'Sub to Run when Test RegEx button is pressed
 sub cmdTextBox
  dim string1, Re,s,colMatches,Test,ResultArr()
 
  'Configure Regular Expression
  set Re = new RegExp
  Re.Pattern = ExprStrin.TextBox.value
 
  ' Error if pattern is blank
  if Re.Pattern = "" Then
         strError = "<font color=red>Please enter a Regular Expression!</font>"
     DataAr1.InnerHTML = strError
     SubAr1.InnerHTML = strError
     strError = ""
 
  'Move on pattern is not blank
  else
     If ExprStrin.GlobalCheckBox.checked Then    'Set Global attribute according to checkbox
         Re.Global = true
     Else
         Re.Global = false
     End If
    
     If ExprStrin.caseCheckbox.checked Then    'Set IgnoreCase attribute according to checkbox
         Re.IgnoreCase = True
     Else
         Re.IgnoreCase = False
     End If
 
     If ExprStrin.MultilineCheckBox.checked Then    'Set Multiline attribute according to checkbox
           Re.Multiline = True
       Else
           Re.Multiline = False
       End If
 
     s = ExprStrin.StringBox.value
    
     'Error if string to search is blank
     if s = "" Then
             strError = "<font color=red>Search String cannot be left blank!</font>"
         DataAr1.InnerHTML = strError
         SubAr1.InnerHTML = strError
         strError = ""
        
     ' Test regex if string is not blank
     else
    
         'If a match is found...
         if Re.Test(s) then
             'Collect and Output Matches
             Set colMatches = Re.Execute(s)
             counter = 0
             numMatches = colMatches.count
             for each Test in colMatches
                 ReDim Preserve ResultArr(counter + 1)
                 ResultArr(counter) = Test.value
                 counter = counter + 1
             next
             dim tempstring
             for count2 = 0 to counter - 1
                 tempstring = tempstring & "<b>Match " & count2+1 & ": </b>" & ResultArr(count2) & "<br>"
             next
             DataAr1.InnerHTML = "<b>The following matches were found:</b><br>" & tempstring
            
             'Collect SubMatches and Store them in a String
             subMatchesString = ""
             For i=0 to numMatches-1    'Loop through each match
                 Set myMatch = colMatches(i)
                 numSubMatches = myMatch.submatches.count
                 If numSubMatches > 0 Then    'Loop through each submatch in current match
                     subMatchesString = subMatchesString & "<b>Submatches for Match " & i+1 & "</b><br>"
                     For j=0 to numSubMatches-1
                         subMatchesString = subMatchesString & myMatch.SubMatches(j) & "<br>"
                     Next
                 End If
             Next
            
             'Output submatches to correct field
             SubAr1.InnerHTML = subMatchesString
                
         'If no match is found output error and sub strings
         else
             DataAr1.InnerHTML = "No match was found for the regular expression."
             ClearSubs
         end if
     end if
  end if
 
  'Clear things up
  Set Re = Nothing
  Set colMatches = nothing
 end sub
 
 'Sub to Run when Clear Results and submatches when button is pressed 
 sub ClearDataAr1
  DataAr1.InnerHTML = "Results Cleared!"
  SubAr1.InnerHTML = "Results Cleared!"
 end sub
 
 
 sub loadfiles
   retVal = "<input type=file name=xmlname> <br> <input type=button value=Assimilate onclick=fileLoader Title=""Click to load settings into App"">"
   Loader.InnerHTML = retVal
   ExprStrin.Saver.disabled = True
   ExprStrin.Templ2.Disabled = True
   exprstrin.xmlname.style.backgroundcolor = "C0C0C0"
 end sub 
 
 sub CloseFile
   Loader.InnerHTML = ""
   Loader2.InnerHTML = ""
   ExprStrin.Loader.Disabled = False
   ExprStrin.Saver.disabled = False
   ExprStrin.Templ2.Disabled = false
 end sub
 
 sub fileLoader
   set fileObj = CreateObject("Scripting.FileSystemObject")
   if ExprStrin.xmlname.value = "" then
       Loader2.InnerHTML= "<font color=red>Enter a filename</font>"
   else
       file = ExprStrin.xmlname.value
   end if 
   if fileObj.FileExists(file) then 
       set objStream = fileObj.OpenTextFile (file, _
           1,false,0)
       opened = true 
   else 
       Loader2.InnerHTML= "<font color=red size=+1>File not found</font>"
       opened = false
   end if
   if opened then
       Loader2.InnerHTML= ""
       contents = ObjStream.Readall
       contents2 = split(contents,"-------")
       expr = Replace(contents2(0),VbnewLine,"")
       if instr(len(contents2(1))-1,contents2(1),vbnewline) then
           stringer = Left(cstr(contents2(1)),len(cstr(contents2(1)))-2)
           stringer = right(stringer,len(stringer) -2 )
       else
           Stringer = contents2(1)
       end if
       ig = Replace(contents2(2),vbnewline,"")
       gs = Replace(contents2(3),vbnewline,"")
       ml = Replace(contents2(4),vbnewline,"")
       'Set hta vars back to loaded values
       ExprStrin.TextBox.value = expr
       ExprStrin.StringBox.value = Stringer
       if ig then 
           ExprStrin.caseCheckbox.checked = True
       else 
           ExprStrin.caseCheckbox.checked = False
       end if 
       if gs then 
           ExprStrin.GlobalCheckBox.Checked = True
       else 
           ExprStrin.GlobalCheckBox.Checked = false
       end if 
       if ml then 
           ExprStrin.MultilineCheckBox.checked = true
       else
           ExprStrin.MultilineCheckBox.checked = False
       end if
   else 
       expr =""
       stringer = ""
       ig = ""
       gs = ""
       ml = ""
   end if 
 set fileObj = Nothing
 End sub
 
 sub TmpInner
   Loader2.InnerHTML = ""
   Loader.InnerHTML= "Enter a filename for template<br>" & _
                     "<input type=""Text"" ""id=Templ"" name=""Templ"" value="""">" & _
                     "<input type=""Button"" value=""Save"" onClick=""SaveTmpl"" Title=""Click after entering filename for template to be created"">"
   ExprStrin.Loader.Disabled = true
   ExprStrin.Saver.disabled = true
   ExprStrin.Templ.style.backgroundcolor = "C0C0C0"
   
 end sub 
 
 sub SaveTmpl
   set fileObj = CreateObject("Scripting.FileSystemObject")
   file = ExprStrin.Templ.value 
   if file = "" then 
       Loader2.InnerHTML = "<font color=red size=+1>Enter a FileName</font>"
 
   else
       if not (fileObj.FileExists(file)) then
           Loader2.InnerHTML = "File not found. Creating now"
           set file2 = fileObj.CreateTextFile(file)
       else 
           Loader2.InnerHTML = "File existed. Over-writing now!"
           set file2 = fileObj.CreateTextFile(file,True)
       end if 
       file2.writeline ("'Remove this line and put expr here")
       file2.WriteLine ("-------")
       file2.WriteLine ("'Remove this line and enter in string.. Can be multi line")
       file2.WriteLine ("-------")
       file2.WriteLine ("'Remove this line. Enter boolean of Ignore case value")
       file2.WriteLine ("-------")
       file2.WriteLine ("'Remove this line. Enter boolean of Global Search value ")
       file2.WriteLine ("-------")
       file2.WriteLine ("'Remove this line. Enter boolean of MultiLine value")
       file2.close
   end if
   set fileObj = nothing
 end sub
 
 sub SaveSets
   Loader2.InnerHTML = ""
   'load txtbox for save value 
   Loader.InnerHTML= "Enter a filename to save<br>" & _
                     "<input type=""Text"" ""id=Templ"" name=""Templ"" value="""">"  & _
                     "<input type=""button"" value=""Save"" onclick=""SaveSets2"" Title=""Click after entering a filename to save"">"
   ExprStrin.Loader.Disabled = True    
   ExprStrin.Templ2.Disabled = True
   ExprStrin.Templ.style.backgroundcolor = "C0C0C0"
 end sub
 
 sub SaveSets2
   set fileObj = CreateObject("Scripting.FileSystemObject")
   file = ExprStrin.Templ.value 
   'open file for writing
   if file = "" then 
       Loader2.InnerHTML = "<font color=red size=+1>Enter a FileName</font>"
   else
       if not (fileObj.FileExists(file)) then 
           Loader2.InnerHTML = "File not found. Creating now"
           set file2 = fileObj.CreateTextFile(file)
       else 
           Loader2.InnerHTML = "File existed. Over-writing now!"
           set file2 = fileObj.CreateTextFile(file,True)
       end if 
       delim = "-------"
       file2.writeline(ExprStrin.TextBox.value)
       file2.writeline(delim)
       file2.writeline(ExprStrin.StringBox.value)
       file2.writeline(delim)
       file2.writeline( ExprStrin.caseCheckbox.checked)
       file2.writeline(delim)
       file2.writeline(ExprStrin.GlobalCheckBox.Checked)
       file2.writeline(delim)
       file2.writeline(ExprStrin.MultilineCheckBox.checked)
       file2.close
   End if 
       set fileObj = nothing
 end sub
 
 sub Window_onload
   ExprStrin.TextBox.style.backgroundcolor = "C0C0C0"
   ExprStrin.StringBox.style.backgroundcolor = "c2c2c2"
 end sub
 '#################### End VBScript Section ####################
 </script>
 </head>
 
 
 <body STYLE="filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#c2c2c2', EndColorStr='#00CCFF')">
  <form action="some_form_handler.asp" method="post" id="ExprStrin" name="ExprStrin" target="_self">
  <center><h1>Regex Tester</font></h1></center>
     <table align="center">
     
         <tr>
             <td>Enter an expression</td>
             <td><input type="text" id="TextBox" name="TextEntry" value="" tabindex=1 size=66 title="Enter a valid regular expression here"></td>
         </tr>
         <tr>
             <td>Enter a string</td>
             <td><textarea cols=50 rows=4 name="StringBox" tabindex=2 Title="Enter in a string to test Regular expression against"></textarea>
             </td>
         </tr>
     </table>
       <!-- Check boxes and main button locations -->
     <table align="center" cellpadding="5">
         <tr>
             <td><input type=checkbox name="IgnoreCase" ID="CaseCheckBox" tabindex=3 title="Allows the ability to ignore case sensitivity">Ignore Case</td>
             <td><input type=checkbox name="Global" id="GlobalCheckBox" tabindex=4 checked="true" Title="Allows the ability to search the whole string">Global Search</td>
             <td><input type=checkbox name="Multiline" id="MultilineCheckBox" tabindex=5 title="Allows the ability to search multiple line strings">Multiline</td>
             </tr>
             <tr>
             <td><input type="button" value="Clear Results" onClick="ClearDataAr1" size=30 tabindex=6 Title="Clear the results area"></td>
             <td><input type="button" value="Test RegEx" onClick="cmdTextBox" tabindex=7 title="Test regular expression"></td>
             <td><input type = "BUTTON" value = "Reload" onclick = "reloadHTA()"tabindex=8 title="Reload App with default values" ></td>
         </tr>
     </table>
 
     <table align="center" cellpadding="5">
         <tr>
             <td><br><font color=blue size=+1><b>Error or Result display</b></font></td>
         </tr>
     </table>
     <table align="center" >
         <tr>
             <td><span id=DataAr1>Result will display here</span></td>
         </tr>
     </table>
     <table align="center" ID="Table1" cellpadding="5">
         <br>
         <tr><td><font color=blue size=+1><b>Substring Matches Display</b></font></td></tr>
     </table>
     <table align=center >
         <tr>
             <td><span id=SubAr1>Substrings will display here</span></td>
         </tr>
     </table>
     <table align=center cellpadding="5"><br><br>
       <tr>
           <td><font color=blue size=+1>Import/Export data from file</font><br><input type="button" value="Load" onClick="loadfiles" id="loader" Title="Select to enable loading options">
               <input type="button" value="Template" onClick="TmpInner" id="Templ2" Title="Allows the creation of a default template">
               <input type="button" value="Save" onclick="SaveSets" id="Saver" Title="Allows you to save current settings to a file">
               <input type="button" Value="Hide" onClick="CloseFile" Title="Hides save/template options"></td>
     </tr>
       <tr>
       <td><span id=Loader></span></td>
       </tr>
       <tr><td><span id=Loader2></span></td></tr>
   </table>
  </form>
 </body>
 </html>
 
<message edited by mikeock on Thursday, July 27, 2006 2:29 AM>
My sig sucks!
 
#1
    ehvbs

    • Total Posts : 3320
    • Scores: 110
    • Reward points : 0
    • Joined: 6/22/2005
    • Location: Germany
    • Status: offline
    RE: Regular expression tester Thursday, June 29, 2006 10:16 AM (permalink)
    4
    Hi mikeok,

    thanks for your useful script. I had real fun studying it. Perhaps you
    are interested in two additions:

    (1) I like to test my .HTAs immediately while I'm tinkering with the
        code; .HTMLs can be reloaded using the browser's button, for .HTAs
        I usually add a button and this reloadHTA() Sub.
        
    (2) There is another RegExps property that was undocumented for a long
        time and frequently misunderstood: Multiline. The new VBScript Docs
        mention it for JScript only - so perhaps you'll learn something
        new.

    Additions:
      9:    />
      10:    <script language="VBScript">
      11:    '#################### Start VBScript Section ####################
      12:    
      ----------------------------- (1) ------------------------------------------------
      13:    ''= refreshes the HTA page, which includes re-running any Windows_Onload code
      14:    ' ============================================================================
      15:    Sub reloadHTA()
      16:      location.reload( True )
      17:    End Sub
      ----------------------------------------------------------------------------------
      18:    
      12:    'Sub to Run when Test RegEx button is pressed
      13:    sub cmdTextBox
      14:       dim string1, Re,s,colMatches,Test,ResultArr()
      
      35:           Else
      36:               Re.IgnoreCase = False
      37:           End If
      45:    
      ----------------------------- (2) ------------------------------------------------
      46:           If ExprStrin.MultilineCheckBox.checked Then    'Set Multiline attribute according to checkbox
      47:               Re.Multiline = True
      48:           Else
      49:               Re.Multiline = False
      50:           End If
      ----------------------------------------------------------------------------------
      51:    
      38:           s = ExprStrin.StringBox.value
      39:    
      40:           'Error if string to search is blank
      
      109:       <form action="some_form_handler.asp" method="post" id="ExprStrin" name="ExprStrin" target="_self">
      110:           <table align="center">
      ----------------------------- (1) ------------------------------------------------
      111:               <tr>
      126:                 <input type = "BUTTON" value = "reload" onclick = "reloadHTA()">
      127:               </tr>
      ----------------------------------------------------------------------------------
      128:    
      129:               <tr>
      112:                   <td>Enter an expression</td>
      113:                   <td><input type="text" id="TextBox" name="TextEntry" value="" tabindex=1 size=66></td>
      114:               </tr>
      
      122:               <tr>
      123:                   <td><input type=checkbox name="IgnoreCase" ID="CaseCheckBox" tabindex=-1>Ignore Case</td>
      124:                   <td><input type=checkbox name="Global" id="GlobalCheckBox" tabindex=-1>Global Search</td>
      ----------------------------- (2) ------------------------------------------------
      143:                   <td><input type=checkbox name="Multiline" id="MultilineCheckBox" tabindex=-1>Multiline</td>
      ----------------------------------------------------------------------------------
      125:                   <td><input type="button" value="Clear Results" onClick="ClearDataAr1" size=30 tabindex=3><td>
      126:                   <td><input type="button" value="Test RegEx" onClick="cmdTextBox" tabindex=4</td>
      127:               </tr>
      

    I think it shows the quality of your code that another programmer could
    understand and add to your script in such a painless way. I hope you will
    like my additions as much as I liked your "Regular expression tester"

    ehvbs
     
     
    #2
      ebgreen

      • Total Posts : 8227
      • Scores: 98
      • Reward points : 0
      • Joined: 7/12/2005
      • Status: offline
      RE: Regular expression tester Friday, June 30, 2006 2:44 AM (permalink)
      0
      Not to diminish the contribution of very well written and useful code, but there is a regular expression testing extension for Firefox that I use all the time when I need to come up with a weird pattern.
      "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
      Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
      http://www.visualbasicscript.com/m_47117/tm.htm
       
      #3
        ehvbs

        • Total Posts : 3320
        • Scores: 110
        • Reward points : 0
        • Joined: 6/22/2005
        • Location: Germany
        • Status: offline
        RE: Regular expression tester Friday, June 30, 2006 3:13 AM (permalink)
        0
        Hi ebgreen,

        you are right and I thank you for the pointer to Sebastian Zartner's Regular Expressions Tester.
        But after using this (or any other non VBScript based tool), you'll still have to check with mikeok's
        script, whether the results in your VBScript will be the same! Just use the MultiLine feature as
        a test case, you'll be surprised!

        ehvbs


         
        #4
          mikeock

          • Total Posts : 124
          • Scores: 1
          • Reward points : 0
          • Joined: 6/8/2006
          • Status: offline
          RE: Regular expression tester Friday, June 30, 2006 4:59 AM (permalink)
          0
          Thanks for the input!
          I will look at rolling the those other options into this.


          My sig sucks!
           
          #5
            kirrilian

            • Total Posts : 629
            • Scores: 3
            • Reward points : 0
            • Joined: 3/15/2005
            • Location:
            • Status: offline
            RE: Regular expression tester Thursday, July 06, 2006 6:35 AM (permalink)
            5
            Thanks for this regex tester, it's much easier to use than some of the others I've tried and it is vbs specific for some stuff.

            I have already merged it and cleaned it up a little bit, the code is below.

            also ehvbs, it is difficult to copy and paste your stuff with the line numbers included ;)

            Suggestions:
            Check for "preceding" symbols such as the * symbol, it created an error when I searched for *test in testing
            Add in functionality for the replace method, this would be nice to have.


             <html>
             <head>
                <title>Regex Tester</title>
             <HTA:APPLICATION
                icon = "c:\icons\hate.ico"
                Caption = "yes"
                Version = "1.1(a)"
             />
             <script language="VBScript">
             '#################### Start VBScript Section ####################
             
             ''= refreshes the HTA page, which includes re-running any Windows_Onload code
             '' ============================================================================
              Sub reloadHTA()
                  location.reload( True )
              End Sub
             
             'Sub to Run when Test RegEx button is pressed
             sub cmdTextBox
                dim string1, Re,s,colMatches,Test,ResultArr()
               
                'Configure Regular Expression
                set Re = new RegExp
                Re.Pattern = ExprStrin.TextBox.value
               
                ' Error if pattern is blank
                if Re.Pattern = "" Then
                        strError = "<font color=red>Please enter a Regular Expression!</font>"
                    DataAr1.InnerHTML = strError
                    SubAr1.InnerHTML = strError
                    strError = ""
               
                'Move on pattern is not blank
                else
                    If ExprStrin.GlobalCheckBox.checked Then    'Set Global attribute according to checkbox
                        Re.Global = true
                    Else
                        Re.Global = false
                    End If
                   
                    If ExprStrin.caseCheckbox.checked Then    'Set IgnoreCase attribute according to checkbox
                        Re.IgnoreCase = True
                    Else
                        Re.IgnoreCase = False
                    End If
             
                    If ExprStrin.MultilineCheckBox.checked Then    'Set Multiline attribute according to checkbox
                          Re.Multiline = True
                      Else
                          Re.Multiline = False
                      End If
             
                    s = ExprStrin.StringBox.value
             
                   
                    'Error if string to search is blank
                    if s = "" Then
                            strError = "<font color=red>Search String cannot be left blank!</font>"
                        DataAr1.InnerHTML = strError
                        SubAr1.InnerHTML = strError
                        strError = ""
                       
                    ' Test regex if string is not blank
                    else
                   
                        'If a match is found...
                        if Re.Test(s) then
                            'Collect and Output Matches
                            Set colMatches = Re.Execute(s)
                            counter = 0
                            numMatches = colMatches.count
                            for each Test in colMatches
                                ReDim Preserve ResultArr(counter + 1)
                                ResultArr(counter) = Test.value
                                counter = counter + 1
                            next
                            dim tempstring
                            for count2 = 0 to counter - 1
                                tempstring = tempstring & "<b>Match " & count2+1 & ": </b>" & ResultArr(count2) & "<br>"
                            next
                            DataAr1.InnerHTML = "<b>The following matches were found:</b><br>" & tempstring
                           
                            'Collect SubMatches and Store them in a String
                            subMatchesString = ""
                            For i=0 to numMatches-1    'Loop through each match
                                Set myMatch = colMatches(i)
                                numSubMatches = myMatch.submatches.count
                                If numSubMatches > 0 Then    'Loop through each submatch in current match
                                    subMatchesString = subMatchesString & "<b>Submatches for Match " & i+1 & "</b><br>"
                                    For j=0 to numSubMatches-1
                                        subMatchesString = subMatchesString & myMatch.SubMatches(j) & "<br>"
                                    Next
                                End If
                            Next
                           
                            'Output submatches to correct field
                            SubAr1.InnerHTML = subMatchesString
                               
                        'If no match is found output error and sub strings
                        else
                            DataAr1.InnerHTML = "No match was found for the regular expression."
                            ClearSubs
                        end if
                    end if
                end if
               
                'Clear things up
                Set Re = Nothing
                Set colMatches = nothing
             end sub
             
             'Sub to Run when Clear Results button is pressed
             sub ClearDataAr1
                DataAr1.InnerHTML = "Results Cleared!"
                ClearSubs
             end sub
             
             'Sub to clear submatches
             sub ClearSubs
                SubAr1.InnerHTML = "Results Cleared!"
             End sub
             '#################### End VBScript Section ####################
             </script>
             </head>
             
             <body>
                <form action="some_form_handler.asp" method="post" id="ExprStrin" name="ExprStrin" target="_self">
                <center><h1>Regex Tester</h1></center>
                    <table align="center">
                    
                        <tr>
                            <td>Enter an expression</td>
                            <td><input type="text" id="TextBox" name="TextEntry" value="" tabindex=1 size=66></td>
                        </tr>
                        <tr>
                            <td>Enter a string</td>
                            <td><textarea cols=50 rows=4 name="StringBox" tabindex=2></textarea>
                            </td>
                        </tr>
                    </table>
                    <table align="center" cellpadding="5">
                        <tr>
                            <td><input type=checkbox name="IgnoreCase" ID="CaseCheckBox" tabindex=-1>Ignore Case</td>
                            <td><input type=checkbox name="Global" id="GlobalCheckBox" tabindex=-1>Global Search</td>
                            <td><input type=checkbox name="Multiline" id="MultilineCheckBox" tabindex=-1>Multiline</td>
                            </tr>
                            <tr>
                            <td><input type="button" value="Clear Results" onClick="ClearDataAr1" size=30 tabindex=3></td>
                            <td><input type="button" value="Test RegEx" onClick="cmdTextBox" tabindex=4></td>
                            <td><input type = "BUTTON" value = "Restart" onclick = "reloadHTA()"tabindex=4></td>
                        </tr>
                    </table>
             
                    <table align="center">
                        <tr>
                            <td><br><font color=blue size=+1><b>Error or Result display</b></font></td>
                        </tr>
                    </table>
                    <table align="center" >
                        <tr>
                            <td><span id=DataAr1>Result will display here</span></td>
                        </tr>
                    </table>
                    <table align="center" ID="Table1">
                        <br>
                        <tr><td><font color=blue size=+1><b>Substring Matches Display</b></font></td></tr>
                    </table>
                    <table align=center >
                        <tr>
                            <td><span id=SubAr1>Substrings will display here</span></td>
                        </tr>
               
                    </table>
                </form>
             </body>
             </html>
             


            Have you searched [url="http://www.google.com"]here [/url]?
            [url="http://tinyurl.com/as7xm"]VBScript Fundamentals[/url]
            [url="http://kirrilian.dyndns.org/projects/code/"]My Site[/url]
             
            #6
              mikeock

              • Total Posts : 124
              • Scores: 1
              • Reward points : 0
              • Joined: 6/8/2006
              • Status: offline
              RE: Regular expression tester Thursday, July 06, 2006 6:57 AM (permalink)
              0
              Nice. I was acutally in the process of rolling the new settings in when I saw your post.

              Thanks! Saves me a bit of time.

              What exactly does the Multiline funtion do?

              I see that it can be enabled but do we need to call against or just enabl it to see the difference?
              My sig sucks!
               
              #7
                ehvbs

                • Total Posts : 3320
                • Scores: 110
                • Reward points : 0
                • Joined: 6/22/2005
                • Location: Germany
                • Status: offline
                RE: Regular expression tester Thursday, July 06, 2006 7:55 AM (permalink)
                0
                Hi mikeok,

                Straight from the VBScript Docs:

                If multiline is false, "^" matches the position at the beginning of a string, and "$" matches the position
                at the end of a string. If multiline is true, "^" matches the position at the beginning of a string as well
                as the position following a "\n" or "\r", and "$" matches the position at the end of a string and the position
                 preceding "\n" or "\r".


                Hi kirrilian,

                sorry about the inconvenient line numbers, but

                   (1) I wanted to mark the positions in mikeok's code clearly where my proposed additions
                         should be added

                   (2) If your editor doesn't have a column mode, you can always use my (transfor)mator
                         tool to add/remove line numbers painlessly.

                ehvbs

                 
                #8
                  kirrilian

                  • Total Posts : 629
                  • Scores: 3
                  • Reward points : 0
                  • Joined: 3/15/2005
                  • Location:
                  • Status: offline
                  RE: Regular expression tester Thursday, July 06, 2006 7:56 AM (permalink)
                  0
                  all you have to do is check the box,

                         If ExprStrin.MultilineCheckBox.checked Then    'Set Multiline attribute according to checkbox
                               Re.Multiline = True
                           Else
                               Re.Multiline = False
                           End If

                  however, im not sure what the multiline flag does though.
                  Have you searched [url="http://www.google.com"]here [/url]?
                  [url="http://tinyurl.com/as7xm"]VBScript Fundamentals[/url]
                  [url="http://kirrilian.dyndns.org/projects/code/"]My Site[/url]
                   
                  #9
                    mikeock

                    • Total Posts : 124
                    • Scores: 1
                    • Reward points : 0
                    • Joined: 6/8/2006
                    • Status: offline
                    RE: Regular expression tester Thursday, July 06, 2006 8:14 AM (permalink)
                    0
                    ehvbs,


                    Thanks for the explanation. It looks a lot like what you would see in other langauges and makes alot more sense now,
                    My sig sucks!
                     
                    #10
                      ehvbs

                      • Total Posts : 3320
                      • Scores: 110
                      • Reward points : 0
                      • Joined: 6/22/2005
                      • Location: Germany
                      • Status: offline
                      RE: Regular expression tester Thursday, July 06, 2006 8:23 AM (permalink)
                      0
                      Hi mikeok,

                      your are welcome. By the way - what do you think about adding some persistency to your
                      Regular expression tester? It would be great, if you could save RegExps, options, test data,
                      and comments/explanations -  perhaps even post samples here, that could be loaded
                      and studied.

                      ehvbs (just starting to dream)
                       
                      #11
                        mikeock

                        • Total Posts : 124
                        • Scores: 1
                        • Reward points : 0
                        • Joined: 6/8/2006
                        • Status: offline
                        RE: Regular expression tester Thursday, July 06, 2006 8:26 AM (permalink)
                        0
                        That is an intersting idea... I think that would be very cool and the tool would become that much more robust.....
                        Maybe you could use a txt file that has everything in a certain order, click load from hta and all of the fields are auto filled out?

                        Dunno just throwing out ideas seeing what others think!
                        My sig sucks!
                         
                        #12
                          kirrilian

                          • Total Posts : 629
                          • Scores: 3
                          • Reward points : 0
                          • Joined: 3/15/2005
                          • Location:
                          • Status: offline
                          RE: Regular expression tester Thursday, July 06, 2006 9:04 AM (permalink)
                          0
                          could one of you share what the multiline flag does?

                          it seems to be poorly documented...
                          Have you searched [url="http://www.google.com"]here [/url]?
                          [url="http://tinyurl.com/as7xm"]VBScript Fundamentals[/url]
                          [url="http://kirrilian.dyndns.org/projects/code/"]My Site[/url]
                           
                          #13
                            ehvbs

                            • Total Posts : 3320
                            • Scores: 110
                            • Reward points : 0
                            • Joined: 6/22/2005
                            • Location: Germany
                            • Status: offline
                            RE: Regular expression tester Thursday, July 06, 2006 10:32 AM (permalink)
                            0
                            Start a version of mikeok's .hta with the multiline code added. Enter RegExp
                               ^a
                            (looking for an "a" at start) and the test data
                               a
                               b
                               a
                               b
                            Enable Global and Test: one match (the first "a", because the second one isn't at the
                            start). Activate Multiline and Test: two matches, because now the ^ means "at the
                            start of the whole string and at the start of each line (after the preceeding line break)

                            Or - in the much clearer words of the VBScript Docs -

                            If multiline is false, "^" matches the position at the beginning of a string, and "$" matches the position
                            at the end of a string. If multiline is true, "^" matches the position at the beginning of a string as well
                            as the position following a "\n" or "\r", and "$" matches the position at the end of a string and the
                            position preceding "\n" or "\r".


                             
                            #14
                              kirrilian

                              • Total Posts : 629
                              • Scores: 3
                              • Reward points : 0
                              • Joined: 3/15/2005
                              • Location:
                              • Status: offline
                              RE: Regular expression tester Friday, July 07, 2006 6:39 AM (permalink)
                              0
                              excellent explanation!

                              and a very handy option if needed indeed
                              Have you searched [url="http://www.google.com"]here [/url]?
                              [url="http://tinyurl.com/as7xm"]VBScript Fundamentals[/url]
                              [url="http://kirrilian.dyndns.org/projects/code/"]My Site[/url]
                               
                              #15
                                mikeock

                                • Total Posts : 124
                                • Scores: 1
                                • Reward points : 0
                                • Joined: 6/8/2006
                                • Status: offline
                                RE: Regular expression tester Friday, July 14, 2006 6:07 AM (permalink)
                                0
                                Ok new features are almost complete.
                                Currently I am able to load a file with an expression and string. you also can pass in boolean values for the check boxes.
                                I am working on a self generating template. This ensure that the file loading process works correctly.
                                The other feature that is being added is a save button. This will allow you to save your current work to a text file and reload it later.
                                Dunno about ETA. 3 days so far to get the load portion working so within the next week or so I will throw a new version this way!
                                My sig sucks!
                                 
                                #16
                                  mikeock

                                  • Total Posts : 124
                                  • Scores: 1
                                  • Reward points : 0
                                  • Joined: 6/8/2006
                                  • Status: offline
                                  RE: Regular expression tester Monday, July 17, 2006 5:15 AM (permalink)
                                  0
                                  Ok here is version 2.0.

                                  New features:
                                    -Ability to save current work to text file.
                                    -Ability to load text files and propagate all textboxes/ checkboxes
                                    -Ability to create a text file te,plate.
                                        allows you to do all the work in a text file, load and then test it...

                                  I cannot figure out how to do the site code tags... (Help please?)

                                  here is the new code!

                                   <html>
                                   <head>
                                     <title>Regex Tester</title>
                                   <HTA:APPLICATION
                                     icon = "c:\icons\hate.ico"
                                     Caption = "yes"
                                     Version = "2.0"
                                   />
                                   <!-- Author : Mike D Adams Mikeock01@hotmail.com
                                       Thanks to Jared Franklin for the submatches portion. 
                                       Thanks to all the suggestion and help from the users of the visualbasicscript.com forums-->
                                   <script language="VBScript">
                                   '#################### Start VBScript Section ####################
                                   
                                   ''= refreshes the HTA page, which includes re-running any Windows_Onload code
                                   '' ============================================================================
                                   Sub reloadHTA()
                                       location.reload( True )
                                   End Sub
                                   
                                   'Sub to Run when Test RegEx button is pressed
                                   sub cmdTextBox
                                     dim string1, Re,s,colMatches,Test,ResultArr()
                                    
                                     'Configure Regular Expression
                                     set Re = new RegExp
                                     Re.Pattern = ExprStrin.TextBox.value
                                    
                                     ' Error if pattern is blank
                                     if Re.Pattern = "" Then
                                             strError = "<font color=red>Please enter a Regular Expression!</font>"
                                         DataAr1.InnerHTML = strError
                                         SubAr1.InnerHTML = strError
                                         strError = ""
                                    
                                     'Move on pattern is not blank
                                     else
                                         If ExprStrin.GlobalCheckBox.checked Then    'Set Global attribute according to checkbox
                                             Re.Global = true
                                         Else
                                             Re.Global = false
                                         End If
                                        
                                         If ExprStrin.caseCheckbox.checked Then    'Set IgnoreCase attribute according to checkbox
                                             Re.IgnoreCase = True
                                         Else
                                             Re.IgnoreCase = False
                                         End If
                                   
                                         If ExprStrin.MultilineCheckBox.checked Then    'Set Multiline attribute according to checkbox
                                               Re.Multiline = True
                                           Else
                                               Re.Multiline = False
                                           End If
                                   
                                         s = ExprStrin.StringBox.value
                                   
                                        
                                         'Error if string to search is blank
                                         if s = "" Then
                                                 strError = "<font color=red>Search String cannot be left blank!</font>"
                                             DataAr1.InnerHTML = strError
                                             SubAr1.InnerHTML = strError
                                             strError = ""
                                            
                                         ' Test regex if string is not blank
                                         else
                                        
                                             'If a match is found...
                                             if Re.Test(s) then
                                                 'Collect and Output Matches
                                                 Set colMatches = Re.Execute(s)
                                                 counter = 0
                                                 numMatches = colMatches.count
                                                 for each Test in colMatches
                                                     ReDim Preserve ResultArr(counter + 1)
                                                     ResultArr(counter) = Test.value
                                                     counter = counter + 1
                                                 next
                                                 dim tempstring
                                                 for count2 = 0 to counter - 1
                                                     tempstring = tempstring & "<b>Match " & count2+1 & ": </b>" & ResultArr(count2) & "<br>"
                                                 next
                                                 DataAr1.InnerHTML = "<b>The following matches were found:</b><br>" & tempstring
                                                
                                                 'Collect SubMatches and Store them in a String
                                                 subMatchesString = ""
                                                 For i=0 to numMatches-1    'Loop through each match
                                                     Set myMatch = colMatches(i)
                                                     numSubMatches = myMatch.submatches.count
                                                     If numSubMatches > 0 Then    'Loop through each submatch in current match
                                                         subMatchesString = subMatchesString & "<b>Submatches for Match " & i+1 & "</b><br>"
                                                         For j=0 to numSubMatches-1
                                                             subMatchesString = subMatchesString & myMatch.SubMatches(j) & "<br>"
                                                         Next
                                                     End If
                                                 Next
                                                
                                                 'Output submatches to correct field
                                                 SubAr1.InnerHTML = subMatchesString
                                                    
                                             'If no match is found output error and sub strings
                                             else
                                                 DataAr1.InnerHTML = "No match was found for the regular expression."
                                                 ClearSubs
                                             end if
                                         end if
                                     end if
                                    
                                     'Clear things up
                                     Set Re = Nothing
                                     Set colMatches = nothing
                                   end sub
                                   
                                   'Sub to Run when Clear Results button is pressed
                                   sub ClearDataAr1
                                     DataAr1.InnerHTML = "Results Cleared!"
                                     ClearSubs
                                   end sub
                                   
                                   'Sub to clear submatches
                                   sub ClearSubs
                                     SubAr1.InnerHTML = "Results Cleared!"
                                   End sub
                                   
                                   sub loadfiles
                                       retVal = "<input type=file name=xmlname> <br> <input type=button value=Assimilate onclick=fileLoader>"
                                       Loader.InnerHTML = retVal
                                   end sub 
                                   
                                   sub CloseFile
                                       Loader.InnerHTML = ""
                                       Loader2.InnerHTML = ""
                                   end sub
                                   
                                   sub fileLoader
                                       set fileObj = CreateObject("Scripting.FileSystemObject")
                                       if ExprStrin.xmlname.value = "" then
                                           Loader2.InnerHTML= "<font color=red>Enter a filename</font>"
                                       else
                                           file = ExprStrin.xmlname.value
                                       end if 
                                       if fileObj.FileExists(file) then 
                                           set objStream = fileObj.OpenTextFile (file, _
                                               1,false,0)
                                           opened = true 
                                       else 
                                           Loader2.InnerHTML= "<font color=red>File not found</font>"
                                           opened = false
                                       end if
                                       if opened then
                                           Loader2.InnerHTML= ""
                                           contents = ObjStream.Readall
                                           contents2 = split(contents,"-------")
                                           expr = Replace(contents2(0),VbnewLine,"")
                                           if instr(len(contents2(1))-1,contents2(1),vbnewline) then
                                               stringer = Left(cstr(contents2(1)),len(cstr(contents2(1)))-2)
                                               stringer = right(stringer,len(stringer) -2 )
                                           else
                                               Stringer = contents2(1)
                                           end if
                                           ig = Replace(contents2(2),vbnewline,"")
                                           gs = Replace(contents2(3),vbnewline,"")
                                           ml = Replace(contents2(4),vbnewline,"")
                                           'Set hta vars back to loaded values
                                           ExprStrin.TextBox.value = expr
                                           ExprStrin.StringBox.value = Stringer
                                           if ig then 
                                               ExprStrin.caseCheckbox.checked = True
                                           else 
                                               ExprStrin.caseCheckbox.checked = False
                                           end if 
                                           if gs then 
                                               ExprStrin.GlobalCheckBox.Checked = True
                                           else 
                                               ExprStrin.GlobalCheckBox.Checked = false
                                           end if 
                                           if ml then 
                                               ExprStrin.MultilineCheckBox.checked = true
                                           else
                                               ExprStrin.MultilineCheckBox.checked = False
                                           end if
                                       else 
                                           expr =""
                                           stringer = ""
                                           ig = ""
                                           gs = ""
                                           ml = ""
                                       end if 
                                   set fileObj = Nothing
                                   End sub
                                   
                                   sub TmpInner
                                       Loader2.InnerHTML = ""
                                       Loader.InnerHTML= "Enter a filename for template<br>" & _
                                                         "<input type=""Text"" ""id=Templ"" name=""Templ"" value="""">" & _
                                                         "<input type=""Button"" value=""Save"" onClick=""SaveTmpl"">"
                                   end sub 
                                   
                                   sub SaveTmpl
                                       set fileObj = CreateObject("Scripting.FileSystemObject")
                                       file = ExprStrin.Templ.value 
                                       if file = "" then 
                                           Loader2.InnerHTML = "<font color=red>please put in a file name</font>"
                                       end if 
                                       if not (fileObj.FileExists(file)) then
                                           Loader2.InnerHTML = "File not found. Creating now"
                                           set file2 = fileObj.CreateTextFile(file)
                                       else 
                                           Loader2.InnerHTML = "File existed. Over-writing now!"
                                           set file2 = fileObj.CreateTextFile(file,True)
                                       end if 
                                       file2.writeline ("'Remove this line and put expr here")
                                       file2.WriteLine ("-------")
                                       file2.WriteLine ("'Remove this line and enter in string.. Can be multi line")
                                       file2.WriteLine ("-------")
                                       file2.WriteLine ("'Remove this line. Enter boolean of Ignore case value")
                                       file2.WriteLine ("-------")
                                       file2.WriteLine ("'Remove this line. Enter boolean of Global Search value ")
                                       file2.WriteLine ("-------")
                                       file2.WriteLine ("'Remove this line. Enter boolean of MultiLine value")
                                       file2.close
                                       
                                       set fileObj = nothing
                                   end sub
                                   
                                   sub SaveSets
                                       Loader2.InnerHTML = ""
                                       'load txtbox for save value 
                                       Loader.InnerHTML= "Enter a filename to save<br>" & _
                                                         "<input type=""Text"" ""id=Templ"" name=""Templ"" value="""">"  & _
                                                         "<input type=""button"" value=""Save"" onclick=""SaveSets2"">"
                                       
                                   end sub
                                   
                                   sub SaveSets2
                                       set fileObj = CreateObject("Scripting.FileSystemObject")
                                       file = ExprStrin.Templ.value 
                                       'open file for writing
                                       if not (fileObj.FileExists(file)) then 
                                           Loader2.InnerHTML = "File not found. Creating now"
                                           set file2 = fileObj.CreateTextFile(file)
                                       else 
                                           Loader2.InnerHTML = "File existed. Over-writing now!"
                                           set file2 = fileObj.CreateTextFile(file,True)
                                       end if 
                                       delim = "-------"
                                       file2.writeline(ExprStrin.TextBox.value)
                                       file2.writeline(delim)
                                       file2.writeline(ExprStrin.StringBox.value)
                                       file2.writeline(delim)
                                       file2.writeline( ExprStrin.caseCheckbox.checked)
                                       file2.writeline(delim)
                                       file2.writeline(ExprStrin.GlobalCheckBox.Checked)
                                       file2.writeline(delim)
                                       file2.writeline(ExprStrin.MultilineCheckBox.checked)
                                       file2.close
                                       set fileObj = nothing
                                   end sub
                                   '#################### End VBScript Section ####################
                                   </script>
                                   </head>
                                   
                                   <body>
                                     <form action="some_form_handler.asp" method="post" id="ExprStrin" name="ExprStrin" target="_self">
                                     <center><h1>Regex Tester</h1></center>
                                         <table align="center">
                                         
                                             <tr>
                                                 <td>Enter an expression</td>
                                                 <td><input type="text" id="TextBox" name="TextEntry" value="" tabindex=1 size=66></td>
                                             </tr>
                                             <tr>
                                                 <td>Enter a string</td>
                                                 <td><textarea cols=50 rows=4 name="StringBox" tabindex=2></textarea>
                                                 </td>
                                             </tr>
                                         </table>
                                         <table align="center" cellpadding="5">
                                             <tr>
                                                 <td><input type=checkbox name="IgnoreCase" ID="CaseCheckBox" tabindex=3>Ignore Case</td>
                                                 <td><input type=checkbox name="Global" id="GlobalCheckBox" tabindex=4>Global Search</td>
                                                 <td><input type=checkbox name="Multiline" id="MultilineCheckBox" tabindex=5>Multiline</td>
                                                 </tr>
                                                 <tr>
                                                 <td><input type="button" value="Clear Results" onClick="ClearDataAr1" size=30 tabindex=6></td>
                                                 <td><input type="button" value="Test RegEx" onClick="cmdTextBox" tabindex=7></td>
                                                 <td><input type = "BUTTON" value = "Restart" onclick = "reloadHTA()"tabindex=8></td>
                                             </tr>
                                         </table>
                                   
                                         <table align="center">
                                             <tr>
                                                 <td><br><font color=blue size=+1><b>Error or Result display</b></font></td>
                                             </tr>
                                         </table>
                                         <table align="center" >
                                             <tr>
                                                 <td><span id=DataAr1>Result will display here</span></td>
                                             </tr>
                                         </table>
                                         <table align="center" ID="Table1">
                                             <br>
                                             <tr><td><font color=blue size=+1><b>Substring Matches Display</b></font></td></tr>
                                         </table>
                                         <table align=center >
                                             <tr>
                                                 <td><span id=SubAr1>Substrings will display here</span></td>
                                             </tr>
                                         </table>
                                         <table align=center><br><br>
                                           <tr>
                                               <td>Reload settings from a file?<br><input type="button" value="Load" onClick="loadfiles">
                                                   <input type="button" value="Template" onClick="TmpInner">
                                                   <input type="button" value="Save" onclick="SaveSets">
                                                   <input type="button" Value="Close" onClick="CloseFile"></td>
                                         </tr>
                                           <tr>
                                           <td><span id=Loader></span></td>
                                           </tr>
                                           <tr><td><span id=Loader2></span></td></tr>
                                       </table>
                                     </form>
                                   </body>
                                   </html>
                                   
                                   


                                  Let me know what you think..

                                  May be bugs in the new features. If any are seen let me know and I will wrap the fix in!

                                  Update: added e-mail address. Contact for changes etc.
                                  Also added in thanks to all who helped.... This site even got a mention!
                                  <message edited by mikeock on Tuesday, July 18, 2006 3:06 AM>
                                  My sig sucks!
                                   
                                  #17
                                    mikeock

                                    • Total Posts : 124
                                    • Scores: 1
                                    • Reward points : 0
                                    • Joined: 6/8/2006
                                    • Status: offline
                                    RE: Regular expression tester [Updated] Thursday, July 27, 2006 2:19 AM (permalink)
                                    0
                                    Bump
                                    My sig sucks!
                                     
                                    #18
                                      mikeock

                                      • Total Posts : 124
                                      • Scores: 1
                                      • Reward points : 0
                                      • Joined: 6/8/2006
                                      • Status: offline
                                      RE: Regular expression tester [Updated] Thursday, August 03, 2006 2:57 AM (permalink)
                                      0
                                      here is a sample file that can be loaded into the Regex tester. Copy the contents out, save to a text file and load using the new buttons at the bottom.

                                       \w+
                                       -------
                                       multi 
                                       line 
                                       string
                                       
                                       extra 
                                       line breaks 
                                       
                                       
                                       Included!
                                       -------
                                       true
                                       -------
                                       false
                                       -------
                                       true
                                       

                                      My sig sucks!
                                       
                                      #19
                                        ehvbs

                                        • Total Posts : 3320
                                        • Scores: 110
                                        • Reward points : 0
                                        • Joined: 6/22/2005
                                        • Location: Germany
                                        • Status: offline
                                        RE: Regular expression tester [Updated] Thursday, August 03, 2006 10:27 PM (permalink)
                                        5
                                        Hi mikeok,

                                        one sample for your regexptester to demonstrate the lookahead feature
                                        (It excludes "win 3.11" from the resulting match list of operating systems)

                                          (?!pattern) Negative lookahead matches the search string at any
                                                      point where a string not matching pattern begins. This
                                                      is a non-capturing match, that is, the match is not
                                                      captured for possible later use. For example 'Windows
                                                      (?!95|98|NT|2000)' matches "Windows" in "Windows 3.1"
                                                      but does not match "Windows" in "Windows 2000".
                                                      Lookaheads do not consume characters, that is, after a
                                                      match occurs, the search for the next match begins
                                                      immediately following the last match, not after the
                                                      characters that comprised the lookahead.
                                                      (VBScript Docs)

                                          ^\w+ (?!3.11)\S+
                                          -------
                                          win 3.11
                                          win 98
                                          win 95
                                          win 2K
                                          win XP
                                          -------
                                          False
                                          -------
                                          True
                                          -------
                                          True
                                          


                                        and two suggestions for further enhancements:

                                          (1) couldn't you collect all the regexp files (in the .hta directory;
                                              possibly identified by a suitable extension like ".re") in a
                                              combobox and load the selected file on "onchange"?

                                          (2) how about adding a comment field to the regexp's data?

                                        To show what I mean:

                                          (a) The bare bones .hta (I prefer for more complicated apps to separate
                                              code from display/layout) - save as "rt00.hta" in a directory with some
                                              .re2 files
                                          <html>
                                           <head>
                                            <hta:application id = "refilecbx"
                                            />
                                            <title>refilecbx</title>
                                            <meta http-equiv = "Content-Type"        content = "text/html; charset = ISO-8859-1" />
                                            <meta http-equiv = "content-script-type" content = "text/vbscript" />
                                            <script language = "VBScript" src = "rt00.vbs" type = "text/vbscript"></script>
                                          <!-- hey, what's wrong with
                                            <script language = "VBScript" src = "rt00.vbs" type = "text/vbscript"/>
                                          -->
                                           </head>
                                           <body onload = "onloadBody()">
                                            <input type = "BUTTON" value = "reload" onclick = "reloadHTA()">
                                            <hr />
                                            <select id = "cbxReFiles" size = "1" onchange = "onchangeCbxReFiles"></select>
                                            <hr />
                                            <input type = "TEXT" id = "sleRE">
                                            <br />
                                            <textarea id = "mleData"></textarea>
                                            <br />
                                            <input type = "checkbox" id = "cbNoCase"   >Ignore Case
                                            <br />
                                            <input type = "checkbox" id = "cbGlobal"   >Global Search
                                            <br />
                                            <input type = "checkbox" id = "cbMultiline">Multiline
                                            <br />
                                            <textarea id = "mleComment"></textarea>
                                           </body>
                                          </html>
                                          


                                          (b) The bare bones VBScript code - save as "rt00.vbs" in this directory
                                          Option Explicit
                                          
                                          ''= global FS
                                          ' ============================================================================
                                          Dim goFS : Set goFS = CreateObject( "Scripting.FileSystemObject" )
                                          
                                          ''= fills cbxReFiles with file names from 'current' dir
                                          ' ============================================================================
                                          Sub onloadBody()
                                            Dim cbxReFiles : Set cbxReFiles = document.getElementById( "cbxReFiles" )
                                            Dim oFile, oOPT
                                          
                                            For Each oFile In goFS.GetFolder( "." ).Files
                                                If "re2" = LCase( goFS.getExtensionName( oFile.Name ) ) Then
                                                   Set oOPT   = cbxReFiles.document.createElement( "OPTION" )
                                                   oOPT.Text  = oFile.Name
                                                   oOPT.Value = oFile.Path
                                                   cbxReFiles.Options.Add oOPT
                                                End If
                                            Next
                                            cbxReFiles.selectedIndex = -1
                                          End Sub
                                          
                                          ''= loads selected file, fills controls/elements
                                          ' ============================================================================
                                          Sub onchangeCbxReFiles_how_I_got_there()
                                            Dim cbxReFiles : Set cbxReFiles = document.getElementById( "cbxReFiles" )
                                            Dim sFSpec     : sFSpec         = cbxReFiles.Options( cbxReFiles.selectedIndex ).value
                                            MsgBox "must load " + sFSpec
                                            Dim sText : sText = goFS.OpenTextFile( sFSpec ).ReadAll
                                            Dim aTest : aTest = Array( _
                                                      "regexp"         _
                                                    , "data"           _
                                                    , True             _
                                                    , True             _
                                                    , True             _
                                                    , "comment"        _
                                                                     )
                                            setControls( aTest )
                                            MsgBox "real set"
                                            Dim sDelim  : sDelim  = vbCrLf + "-------" + vbCrLf
                                            aTest = Split( sText, sDelim )
                                            setControls( aTest )
                                          End Sub
                                          
                                          Sub onchangeCbxReFiles()
                                            Dim cbxReFiles : Set cbxReFiles = document.getElementById( "cbxReFiles" )
                                            Dim sFSpec     : sFSpec         = cbxReFiles.Options( cbxReFiles.selectedIndex ).value
                                            Dim sText      : sText          = goFS.OpenTextFile( sFSpec ).ReadAll
                                            Dim sDelim     : sDelim         = vbCrLf + "-------" + vbCrLf
                                            Dim aTest      : aTest          = Split( sText, sDelim )
                                            If 5 > UBound( aTest ) Then
                                               ReDim Preserve aTest( 5 )
                                               aTest( 5 ) = "no comment"
                                            End If
                                            setControls( aTest )
                                            cbxReFiles.selectedIndex = -1
                                          End Sub
                                          
                                          ''= puts data (aValues) into controls (elements)
                                          ' ============================================================================
                                          Sub setControls( aValues )
                                            document.getElementById( "sleRE"       ).Value   = aValues( 0 )
                                            document.getElementById( "mleData"     ).Value   = aValues( 1 )
                                            document.getElementById( "cbNoCase"    ).Checked = aValues( 2 )
                                            document.getElementById( "cbGlobal"    ).Checked = aValues( 3 )
                                            document.getElementById( "cbMultiline" ).Checked = aValues( 4 )
                                            document.getElementById( "mleComment"  ).Value   = aValues( 5 )
                                          End Sub
                                          
                                          ''= refreshes the HTA page, which includes re-running any Windows_Onload code
                                          ' yes, I deleted the ()!
                                          ' ============================================================================
                                          Sub reloadHTA()
                                            location.reload True
                                          End Sub
                                          


                                        But as I said - these are suggestions, so please don't feel pestered.

                                        Thanks for your good work!

                                        ehvbs

                                         
                                        #20

                                          Online Bookmarks Sharing: Share/Bookmark
                                          Change Page: 12 > | Showing page 1 of 2, messages 1 to 20 of 22

                                          Jump to:

                                          Current active users

                                          There are 0 members and 1 guests.

                                          Icon Legend and Permission

                                          • New Messages
                                          • No New Messages
                                          • Hot Topic w/ New Messages
                                          • Hot Topic w/o New Messages
                                          • Locked w/ New Messages
                                          • Locked w/o New Messages
                                          • Read Message
                                          • Post New Thread
                                          • Reply to message
                                          • Post New Poll
                                          • Submit Vote
                                          • Post reward post
                                          • Delete my own posts
                                          • Delete my own threads
                                          • Rate post

                                          2000-2012 ASPPlayground.NET Forum Version 3.9