|Languages & Libraries|
|Visual Basic 6|
|XQuery & XPath|
|Regular Expressions Quick Start|
|Regular Expressions Tutorial|
|Replacement Strings Tutorial|
|Applications and Languages|
|Regular Expressions Examples|
|Regular Expressions Reference|
|Replacement Strings Reference|
|About This Site|
|RSS Feed & Blog|
Unlike Visual Basic.NET, which has access to the excellent regular expression support of .NET, good old Visual Basic 6 does not ship with any regular expression support. However, VB6 does make it very easy to use functionality provided by ActiveX and COM libraries.
To use this library in your Visual Basic application, select Project|References in the VB IDE’s menu. Scroll down the list to find the item “Microsoft VBScript Regular Expressions 5.5”. It’s immediately below the “Microsoft VBScript Regular Expressions 1.0” item. Make sure to tick the 5.5 version, not the 1.0 version. The 1.0 version is only provided for backward compatibility. Its capabilities are less than satisfactory.
The only difference between VB6 and VBScript is that you’ll need to use a Dim statement to declare the objects prior to creating them. Here’s a complete code snippet. It’s the two code snippets on the VBScript page put together, with three Dim statements added.
'Prepare a regular expression object Dim myRegExp As RegExp Dim myMatches As MatchCollection Dim myMatch As Match Set myRegExp = New RegExp myRegExp.IgnoreCase = True myRegExp.Global = True myRegExp.Pattern = "regex" Set myMatches = myRegExp.Execute(subjectString) For Each myMatch in myMatches MsgBox(myMatch.Value) Next
Page URL: https://www.regular-expressions.info/vb.html
Page last updated: 24 August 2021
Site last updated: 02 December 2022
Copyright © 2003-2022 Jan Goyvaerts. All rights reserved.