One such library is Microsoft's VBScript scripting library, which has decent regular expression capabilities starting with version 5.5. It implements the regular expression flavor used in JavaScript. This library is part of Internet Explorer 5.5 and later. It is available on all computers running Windows XP, Vista, 7, 8, 8.1, or 10, and previous versions of Windows if the user upgraded to IE 5.5 or later. That includes almost every Windows PC that is used to connect to the Internet.

Internet Explorer 5.5 did not score very high on web standards. There are quite a few differences between its implementation of JavaScript regular expressions and the actual standard. Fortunately, most are corner cases that are not likely to affect you. Modern versions of IE still use the IE 5.5 implementation when rendering web pages in quirks mode. In standards mode, modern versions of IE follow the JavaScript standard very closely. VBScript regular expressions also still use the IE 5.5 implementation, even when a modern version of IE is installed.

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.

After adding the reference, you can see which classes and class members the library provides. Select View|Object Browser in the menu. In the Object Browser, select the "VBScript_RegExp_55" library in the drop-down list in the upper left corner. For a detailed description, see the VBScript regular expression reference on this website. Anything said about JavaScript's flavor of regular expressions in the tutorial also applies to VBScript's flavor. The only exception is the character escape support for \xFF and \uFFFF in the replacement text. JavaScript supports these in string literals, but Visual Basic does not.

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.

Make a Donation

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! Credit cards, PayPal, and Bitcoin gladly accepted.