
![]() |
Interactively create and test regular expressions with RegexBuddy. Create and analyze regex patterns with RegexBuddy's intuitive regex building blocks. Quickly test regular expressions on sample data and files in a safe sandbox. Debug regexes easily with real-time highlighting and informative regex match details. Get your own copy of RegexBuddy now. |
Feel free to test VBScript's RegExp support right here in your browser. The example will only work in Internet Explorer 5.5 or later. Since this tester is implemented in VBScript, it will reflect the features and limitations of VBScript and your version of Internet Explorer. If you're looking for a general-purpose regular expression tester supporting a variety of regex flavors, grab yourself a copy of RegexBuddy.
If clicking one of the buttons does not seem to have any effect, double-click the error indicator in Internet Explorer's status bar. Most likely, there is an error in your regular expression. If your regular expression is valid but does not match the test subject, the tester will pop up a message.
Learn how to use the VBScript RegExp object.
<SCRIPT LANGUAGE="VBScript"><!--
Sub btnTest_OnClick
Set re = New RegExp
re.Pattern = document.demoMatch.regex.value
If re.Test(document.demoMatch.subject.value) Then
msgbox "Successful match", 0, "VBScript Regular Expression Tester"
Else
msgbox "No match", 0, "VBScript Regular Expression Tester"
End If
End Sub
Sub btnMatch_OnClick
Set re = New RegExp
re.Pattern = document.demoMatch.regex.value
Set matches = re.Execute(document.demoMatch.subject.value)
If matches.Count > 0 Then
Set match = matches(0)
msg = "Found match """ & match.Value & _
""" at position " & match.FirstIndex & vbCRLF
If match.SubMatches.Count > 0 Then
For I = 0 To match.SubMatches.Count-1
msg = msg & "Group #" & I+1 & " matched """ & _
match.SubMatches(I) & """" & vbCRLF
Next
End If
msgbox msg, 0, "VBScript Regular Expression Tester"
Else
msgbox "No match", 0, "VBScript Regular Expression Tester"
End If
End Sub
Sub btnMatchGlobal_OnClick
Set re = New RegExp
re.Pattern = document.demoMatch.regex.value
re.Global = True
Set matches = re.Execute(document.demoMatch.subject.value)
If matches.Count > 0 Then
msg = "Found " & matches.Count & " matches:" & vbCRLF
For Each match In Matches
msg = msg & "Found match """ & match.Value & _
""" at position " & match.FirstIndex & vbCRLF
Next
msgbox msg, 0, "VBScript Regular Expression Tester"
Else
msgbox "No match", 0, "VBScript Regular Expression Tester"
End If
End Sub
Sub btnReplace_OnClick
Set re = New RegExp
re.Pattern = document.demoMatch.regex.value
re.Global = True
document.demoMatch.result.value = _
re.Replace(document.demoMatch.subject.value, _
document.demoMatch.replacement.value)
End Sub
' -->
</SCRIPT>
<FORM ID="demoMatch" NAME="demoMatch">
<P>Regexp: <INPUT TYPE=TEXT NAME="regex" VALUE="\bt[a-z]+\b" SIZE=50></P>
<P>Subject string: <INPUT TYPE=TEXT NAME="subject"
VALUE="This is a test of the VBScript RegExp object" SIZE=50></P>
<P><INPUT TYPE=BUTTON NAME="btnTest" VALUE="Test Match">
<INPUT TYPE=BUTTON NAME="btnMatch" VALUE="Show Match">
<INPUT TYPE=BUTTON NAME="btnMatchGlobal" VALUE="Show All Matches"></P>
<P>Replacement text: <INPUT TYPE=TEXT NAME="replacement"
VALUE="replaced" SIZE=50></P>
<P>Result: <INPUT TYPE=TEXT NAME="result"
VALUE="click the button to see the result" SIZE=50></P>
<P><INPUT TYPE=BUTTON NAME="btnReplace" VALUE="Replace"></P>
</FORM>Did this website just save you a trip to the bookstore? Please make a donation to support this site, and you'll get a lifetime of advertisement-free access to this site!
Page URL: http://www.Regular-Expressions.info/vbscriptexample.html
Page last updated: 22 September 2010
Site last updated: 02 February 2012
Copyright © 2003-2012 Jan Goyvaerts. All rights reserved.
| Regex Tools |
| grep |
| PowerGREP |
| RegexBuddy |
| RegexMagic |
| General Applications |
| EditPad Pro |
| Languages & Libraries |
| Delphi |
| GNU (Linux) |
| Groovy |
| Java |
| JavaScript |
| .NET |
| PCRE (C/C++) |
| Perl |
| PHP |
| POSIX |
| PowerShell |
| Python |
| R |
| REALbasic |
| Ruby |
| Tcl |
| VBScript |
| Visual Basic 6 |
| wxWidgets |
| XML Schema |
| XQuery & XPath |
| Databases |
| MySQL |
| Oracle |
| PostgreSQL |
| More Information |
| Introduction |
| Quick Start |
| Tutorial |
| Tools and Languages |
| Examples |
| Books |
| Reference |
| Print PDF |
| About This Site |
| RSS Feed & Blog |
| New! PowerGREP 4 |
| Use regular expressions to search through large numbers of text and binary files. Quickly find the files you are looking for, or extract the information you need. Look through just a handful of files or folders, or scan entire drives and network shares. |
| Search and replace using text, binary data or one or more regular expressions to automate repetitive editing tasks. Preview replacements before modifying files, and stay safe with flexible backup and undo options. |
| Use regular expressions to rename files, copy files, or merge and split the contents of files. Work with plain text files, Unicode files, binary files, compressed files, and files in proprietary formats such as MS Office, OpenOffice, and PDF. Runs on Windows 2000, XP, Vista, and 7. |
| More information |
| Download PowerGREP now |