Export (0) Print
Expand All

Regular Expressions vs. the Like Operator (Visual Basic)

This topic compares and contrasts the Visual Basic Like operator and regular expressions in the .NET Framework.

The following table compares the pattern-specification language syntax for the Like operator with the syntax for regular expressions.

Like operator syntax

Regular expression syntax

The behavior of the Like operator depends on the Option Compare Statement. The default string comparison method for each source file is Option Compare Binary.

Regular expressions work the same regardless of Option Compare.

To match any single character in charlist, use [charlist].

To match any single character in charlist, use [charlist].

To match any single character not in charlist, use [!charlist].

To match any single character not in charlist, use [^charlist].

To match any single digit (0–9), use #.

To match any single digit (0–9), use the character class for decimal digits, \d.

To match any single character, use ?.

To match any single character, specify mutually exclusive character classes for the charlist in [charlist]. For example, [\s\S].

To match zero or more characters, use *.

To match zero or more characters, specify mutually exclusive character classes for the charlist in [charlist]*. For example, [\s\S]*.

To match a special character char, enclose it in brackets: [char].

To match a special character char, precede it with a backslash: \char.

To match any character in a range, use a hyphen () to separate the lower and upper bounds of the range in a charlist.

To match any character in a range, use a hyphen () to separate the lower and upper bounds of the range in a charlist.

Community Additions

ADD
Show:
© 2014 Microsoft