Like (operator)


expression Like pattern


Compares two strings and returns TRUE if the expression matches the given pattern; returns FALSE otherwise.


Case sensitivity is controlled by the Option Compare setting.

The pattern expression can contain special characters that allow more flexible matching:



Evaluates to



Matches a single character.



Matches one or more characters.



Matches any digit.



Matches if the character in question is within the specified range.



Matches if the character in question is not within the specified range.


A range specifies a grouping of characters. To specify a match of any of a group of characters, use the syntax [ABCDE]. To specify a range of characters, use the syntax [A-Z]. Special characters must appear within brackets, such as []*?#.

If expression or pattern is not a string, then both expression and pattern are converted to String variants and compared, returning a Boolean variant. If either variant is Null, then Null is returned.

The following table shows some examples:



TRUE If pattern Is

FALSE If pattern is Is



"E*W", "E*"












"#.#", "#?#"

"###", "#?[!0-9]"




"[ABC]", "[*]"


This example demonstrates various uses of the Like function.

Sub Main()
  a$ = "This is a string variable of 123456 characters"
  b$ = "123.45"
  If a$ Like "[A-Z][g-i]*" Then MsgBox "The first comparison is True."
  If b$ Like "##3.##" Then MsgBox "The second comparison is True."
  If a$ Like "*variable*" Then MsgBox "The third comparison is True."
End Sub

See Also

Operator Precedence (topic); Is (operator); Option Compare (statement).

More information