Quick Start
Tutorial
Search & Replace
Tools & Languages
Examples
Reference
Regex Tools
grep
PowerGREP
RegexBuddy
RegexMagic
General Applications
EditPad Lite
EditPad Pro
Google Docs
Google Sheets
LibreOffice
Notepad++
Languages & Libraries
Boost
C#
Delphi
F#
GNU (Linux)
Groovy
ICU (Unicode)
Java
JavaScript
.NET
PCRE (C/C++)
PCRE2 (C/C++)
Perl
PHP
POSIX
PowerShell
Python
Python.NET and IronPython
R
RE2
Ruby
std::regex
Tcl
TypeScript
VBScript
Visual Basic 6
Visual Basic (.NET)
wxWidgets
XML Schema
XQuery & XPath
Xojo
XRegExp
Databases
Google BigQuery
MySQL
Oracle
PostgreSQL
More on This Site
Introduction
Regular Expressions Quick Start
Regular Expressions Tutorial
Replacement Strings Tutorial
Applications and Languages
Regular Expressions Examples
Regular Expressions Reference
Replacement Strings Reference
Book Reviews
Printable PDF
About This Site
RSS Feed & Blog
PowerGREP—The world’s most powerful tool to flex your regex muscles!
RegexBuddy—The best regex editor and tester for .NET developers!

Using .NET Regular Expressions with Visual Basic

Modern Visual Basic is based on the Microsoft .NET framework and can thus readily access its excellent support for regular expressions. It’s a dramatic improvement from what was available to Visual Basic 6 developers. See the topic about .NET to learn more about the classes in the Systems.Text.RegularExpressions namespace. When you put it all together, you could check whether a regex can match a string in VB.NET with a code snippet like this:

Imports System.Text.RegularExpressions; Dim FoundMatch As Boolean = False Try Dim RegexObj As New Regex("\A\w+\z") FoundMatch = RegexObj.IsMatch(SubjectString) Catch ex As ArgumentException 'Syntax error in the regular expression End Try

No Issues With Backslashes

Visual Basic string literals do not treat the backslash as a metacharacter. You can easily format a regular expression as a VB string by putting double quotes around it and doubling up any double quotes inside the regex. Starting with Visual Basic 14 (Visual Studio 2015), even line breaks are literals inside VB strings. This makes it very convenient to use RegexOptions.IgnorePatternWhitespace to format your regular expression with extra whitespace and line breaks for readability.

| Quick Start | Tutorial | Search & Replace | Tools & Languages | Examples | Reference |

| grep | PowerGREP | RegexBuddy | RegexMagic |

| EditPad Lite | EditPad Pro | Google Docs | Google Sheets | LibreOffice | Notepad++ |

| Boost | C# | Delphi | F# | GNU (Linux) | Groovy | ICU (Unicode) | Java | JavaScript | .NET | PCRE (C/C++) | PCRE2 (C/C++) | Perl | PHP | POSIX | PowerShell | Python | Python.NET and IronPython | R | RE2 | Ruby | std::regex | Tcl | TypeScript | VBScript | Visual Basic 6 | Visual Basic (.NET) | wxWidgets | XML Schema | XQuery & XPath | Xojo | XRegExp |

| Google BigQuery | MySQL | Oracle | PostgreSQL |