String Comparison Functions
AMPS includes several types of string comparison operators:
- Case-Sensitive Exact Matches - The
IN
,=
,BEGINS WITH
,ENDS WITH
, andINSTR
operators do literal matching on the contents of a string. These operators are case-sensitive. - Case-Insensitive Exact Matches - AMPS also provides two case-insensitive operators:
INSTR_I
, a case-insensitive version ofINSTR
, and a case-insensitive equality operator,STREQUAL_I
. - Regular Expression Matches - AMPS also provides full regular expression matching using the
LIKE
operator, described in Regular Expressions.
The =
operator tests whether a field exactly matches the literal string provided.
/status = 'available'
/orderId = 'F327AC'
BEGINS WITH
and ENDS WITH
test whether a field begins or ends with the literal string provided. The operators return TRUE
or FALSE
.
/Department BEGINS WITH ('Engineering')
/path NOT BEGINS WITH ('/public/dropbox')
/filename ENDS WITH ('txt')
/price NOT ENDS WITH ('99')
AMPS allows you to use set comparisons with BEGINS WITH
and ENDS WITH
. In this case, the filter matches if the string in the field begins or ends with any of the strings in the set.
/Department BEGINS WITH ('Engineering', 'Research', 'Technical')
/filename ENDS WITH ('gif', 'png', 'jpg')
The INSTR
operator allows you to check to see if one string occurs within another string. For this operator, you provide two string values. If the second string occurs within the first string, INSTR
returns the position at which the second string starts, or 0 if the second string does not occur within the first string. Notice that the first character of the string is 1 (not 0). For example, the expression below tests whether the string critical
occurs within the /eventLevels
field.
INSTR(/eventLevels, "critical") != 0
AMPS also provides INSTR_I
and STREQUAL_I
functions for performing case-insensitive comparisons.
STREQUAL_I(/couponCode, 'QED') == 1
INSTR_I(/symbolList, 'MSFT') != 0
Following are the list of string comparison functions and operators in AMPS.
= (Equals)
= (Equals)
string1 = string2
Case-sensitive. Returns true if string1
is identical to string2
.
Parameters
string1
: The first string.string2
: The second string.
Returns
true
if the strings are identical, false
otherwise.
BEGINS WITH
BEGINS WITH
string BEGINS WITH (substring1, [substring2, ...])
Case-sensitive. Returns true if string
begins with any of the substrings in the list.
Parameters
string
: The string to check.substring1
: The first substring to check for.substring2
: Optional. Additional substrings to check for.
Returns
true
if the string begins with one of the provided substrings, false
otherwise.
ENDS WITH
ENDS WITH
string ENDS WITH (substring1, [substring2, ...])
Case-sensitive. Returns true if string
ends with any of the substrings in the list.
Parameters
string
: The string to check.substring1
: The first substring to check for.substring2
: Optional. Additional substrings to check for.
Returns
true
if the string ends with one of the provided substrings, false
otherwise.
INSTR
INSTR
INSTR(string, substring)
Case-sensitive. Returns the position at which substring
starts in string
, or 0
if substring
does not occur within string
. This function is not unicode-aware.
Parameters
string
: The string to search within.substring
: The substring to search for.
Returns
The 1-based starting position of the substring, or 0
if not found.
INSTR_I
INSTR_I
INSTR_I(string, substring)
Case-insensitive. Returns the position at which substring
starts in string
, or 0
if substring
does not occur within string
. This function is not unicode-aware.
Parameters
string
: The string to search within.substring
: The substring to search for.
Returns
The 1-based starting position of the substring, or 0
if not found.
STREQUAL_I
STREQUAL_I
STREQUAL_I(string1, string2)
Case-insensitive. Returns true if, when both strings are transformed to the same case, string1
is identical to string2
. This function is not unicode-aware.
Parameters
string1
: The first string.string2
: The second string.
Returns
true
if the strings are identical (case-insensitively), false
otherwise.
LENGTH
LENGTH
LENGTH(string)
Returns the length of the provided string.
Parameters
string
: The string to measure.
Returns
The length of the string.