Find Matches in Array Given a Regular Expression - Example 2
Use regular expressions to search for and match specific patterns ignoring case in flat arrays
Query
array:regex("responses[]", regex="bear$", flags="i")
Introduction
A regular expression is a form of advanced searching that looks for specific patterns, as opposed to certain terms and phrases. You can use a regular expression to find all matches in an array.
In this example, the regular expression is used to search for
patterns where the value
bear
appears at the end of a
value in an array element, ignoring the case.
Step-by-Step
Starting with the source repository events.
- flowchart LR; %%{init: {"flowchart": {"defaultRenderer": "elk"}} }%% repo{{Events}} 0[[Array Manipulation]] result{{Result Set}} repo --> 0 0 --> result style 0 fill:#ff0000,stroke-width:4px,stroke:#000;logscale
array:regex("responses[]", regex="bear$", flags="i")
Searches in the responses array for values that begins with
bear
, ignoring the case (due to thei
flag). Event Result set.
Summary and Results
The queries using the regex expression are used to quickly search and return results for specific values in arrays. Regular expressions are useful when searching for different strings containing the same patterns; such as social security numbers, URLs, email addresses, and other strings that follow a specific pattern.