Regex Tools |
grep |
PowerGREP |
RegexBuddy |
RegexMagic |
General Applications |
EditPad Lite |
EditPad Pro |
Databases |
MySQL |
Oracle |
PostgreSQL |
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>
| Quick Start | Tutorial | Tools & Languages | Examples | Reference | Book Reviews |
| grep | PowerGREP | RegexBuddy | RegexMagic |
| EditPad Lite | EditPad Pro |
| Boost | Delphi | GNU (Linux) | Groovy | Java | JavaScript | .NET | PCRE (C/C++) | PCRE2 (C/C++) | Perl | PHP | POSIX | PowerShell | Python | R | Ruby | std::regex | Tcl | VBScript | Visual Basic 6 | wxWidgets | XML Schema | Xojo | XQuery & XPath | XRegExp |
| MySQL | Oracle | PostgreSQL |
Page URL: https://www.regular-expressions.info/vbscriptexample.html
Page last updated: 24 August 2021
Site last updated: 06 November 2024
Copyright © 2003-2024 Jan Goyvaerts. All rights reserved.