Extracting Matching Text in Strings

AMPS includes a function, REGEXP_MATCH, that returns the first match of text within a string. REGEXP_MATCH can be either a literal match or PCRE pattern to match the text to. If there is no match, then a NULL value is returned.

The following expressions all evaluate as true:

REGEXP_MATCH('sheepdog', 'dog') > 0

REGEXP_MATCH("30dogs", "^[0-9]*") == "30"

The following snippet shows REGEXP_MATCH constructed as a field:

<Field>COALESCE(REGEXP_MATCH(/petDescription, "cat|dog|bear"), "back away slowly, I don't know what that is") as /animal_type</Field>

With the following data:

{"petDescription": "tabby cat"}
{"petDescription": "havanese dog"}
{"petDescription": "grizzly bear"}
{"petDescription": "blue gerbil"}

Would result in:

{"petDescription":"tabby cat","animal_type":"cat"}
{"petDescription":"havanese dog","animal_type":"dog"}
{"petDescription":"grizzly bear","animal_type":"bear"}
{"petDescription":"blue gerbil","animal_type":"back away slowly, I don't know what that is"}
Function
Parameters
Description

REGEXP_MATCH

string to transform, pattern or text to match

Returns the first occurrence of the pattern or text to match, or NULL

Last updated