MATCH_STRING Function

Determines if the first string matches the second string, which can contain wildcards.

Category: String
Returned data type: Boolean

Syntax

MATCH_STRING(string1, string2)

Required Arguments

string1

specifies a string to search; this can be specified as string constant, field name, or expression

Note: If source is NULL, the function returns a NULL value.

string2

specifies a string that represents a search pattern; this can be specified as string constant, field name, or expression

Details

The MATCH_STRING function searches string1 using the search pattern specified in string2. If a match was found, true is returned otherwise, false is returned.

Search strings can include wildcards in the leading (*ABC) and trailing (ABC*) position, or a combination of the two (*ABC*). Wildcards within a string are invalid (A*BC).

A question mark can be used as a wildcard but is matched only to a character. For example, AB? will match ABC, not AB.

To execute a search for a character that is used as a wildcard, precede the character with a backslash. This denotes that the character should be used literally and not as a wildcard. Valid search strings include: *BCD*, *B?D*, *BCDE, *BC?E, *BCD?, ABCD*, AB?D*, ?BCD*, *B??*, *B\?\\* (will match the literal string AB?\E). An invalid example is: AB*DE.

For more complex searches, regular expressions instead of the match_string() function are recommended.

Example

string1 = "Monday is sunny, Tuesday is rainy & Wednesday is windy"

string2 = "Tuesday is"

match = match_string(string1, string2) // outputs false

string2 = "*Tuesday is*"

match = match_string(string1, string2) // outputs true