Skip to main content

LIKE Operator

AMPS also provides a regular expression comparison operator, LIKE, to provide regular expression matching on string values. A pattern is used for the right side of the LIKE operator. A pattern must be provided as a literal, quoted value. For more on regular expressions and the LIKE comparison operator, please see the section on Regular Expressions.

tip

The LIKE operator lets you use PCRE matching for comparisons that other operators can't fully capture. Use AMPS operators where available. The Performance Considerations section has details, including AMPS equivalents for common regular expressions.

The string comparison operators described in the section called String Comparison Functions are usually more efficient than equivalent LIKE expressions, particularly when used to compare multiple literal patterns, or when the only purpose of the regular expression is to perform case-insensitive matching. Use LIKE operations when it is not practical to represent the filter condition with the string comparison operators.

Function or OperatorParametersDescription
LIKE

The string to be compared

The pattern to evaluate the string against

Case-sensitive

Returns true if the string to be compared matches the pattern.

For example, the following filter uses a PCRE backreference to return true for any message where the /state field contains two identical characters in a row.

/state LIKE '(.)\1'

This operator is not unicode-aware.

Regex Performance​

AMPS provides full PCRE support. This means that it is possible to write both efficient, targeted regular expressions and expressions that are inefficient.

Avoid patterns that require extensive backtracking or deep recursion, since patterns using these features can require exponential time to evaluate. Likewise, consider whether a pattern that makes extensive use of alternation (|) or lookahead/lookbehind assertions can be rewritten using AMPS dedicated functions.

When using a regular expression for production purposes that goes beyond simple pattern matching, we recommend evaluating the regular expression for complexity and backtracking cost using a profiling tool. Measure the performance against typical production data where possible, since the input to be matched is a key factor in performance (particularly in backtracking cost).

When measuring against production data, include both typical matching and typical non-matching strings, since the complexity and cost may differ.