LIKE operator
The LIKE operator creates a property that implements string comparison with a pattern. For full-text search, use the separate MATCH operator.
Syntax
searchExpr LIKE compareExpr
Description
The LIKE operator creates a property that returns TRUE if the specified string matches the given pattern. The pattern can include the following wildcard characters:
%(percent sign) - replaces any number of characters, including zero characters. This wildcard is used when the exact content or number of characters in a part of the string is unknown._(underscore) - replaces exactly one character. It is used when the exact location of a single character is required, but the character itself can be anything.
To include the % or _ characters in the pattern as regular characters, they must be escaped using the backslash \ character. Remember, when specifying the pattern using a string literal, to represent the backslash itself, it needs to be doubled: \\.
The case sensitivity of LIKE is determined by the class of searchExpr. For case-insensitive string classes (ISTRING, BPISTRING, TEXT, RICHTEXT, HTMLTEXT), the operator performs a case-insensitive comparison.
Parameters
-
searchExprExpression whose value determines the string being compared.
The value of the expression must belong to one of the string classes.
-
compareExprExpression whose value determines the pattern.
The value of the expression must belong to one of the string classes.
Examples
isReportDocument(Document doc) = name(doc) LIKE '%report%'; // checks if the name contains the word 'report'
isPhoneNumber(STRING str) = str LIKE '(___) ___-____'; // checks if the phone number matches the format
startsWith(STRING str, STRING prefix) = str LIKE prefix + '%'; // checks the beginning of the string
contains(STRING content, STRING str) = content LIKE '%' + str + '%'; // checks if the string contains the substring
containsNew(STRING content, STRING str) = content LIKE '%${str}%'; // same as above, but with string interpolation
escapingExample(STRING str) = str LIKE '__\\%'; // Escaping example. Checks for a two-digit percentage.