Comparing strings with patterns

Syntax

…string-expr… LIKE "pattern"

Typing

STRING -> BOOL

Description

LIKE compares a string expression with a pattern, expressed as a string that can contain the special character percent ('%') that can replace any substring including the empty substring, and the special character underscore ('_') that can match any single character.

If you need to match precisely for any of those special characters you can escape them with the backslach prefix ('\'). Notice though that since backslash is also the default escaping character for strings, and pattern is written as a string, it has to be doubled in practice to serve as a pattern escape character!

The result is true if the left string matches the pattern, or false otherwise.

Note that the pattern cannot be any string expression but must be a string constant.

Examples

expression evaluates to
"foobar" LIKE "foo%" true
"foobar" NOT LIKE "foo" true
"foobar" LIKE "foo\\%" false
"foobar" LIKE "f%r" true
"foobar" NOT LIKE "%oo%" false
"foobar" LIKE "f__b_r" true
"foobar" LIKE "fo_b%" true
"foobar" LIKE "%baz" false
"foobar" LIKE "" false

See Also

String-ends-with operator String-starts-with operator