Function: text.find_all_regex

Finds all matches of a regular expression in a string.

A list of matches is returned, where each match has the starting index (zero-based) of the matched substring and the substring itself. In the case of overlapping matches, only the leftmost match is considered. If the overlapping matches start at the same index, then the longest match is considered.

Arguments

Arguments
source

string

The source string to search.

regexp

string

The regular expression used for the search. Uses RE2 syntax.

Returns

A list of maps, where each map represents a match. The map has the keys index and match whose values are the starting index (int) of the substring and the substring itself (string), respectively. The list is sorted by the index key. If no match is found, an empty list is returned.

Raised exceptions

Exceptions
TypeError If either source or regexp is not a string.
ValueError If regexp is not UTF-8 encoded or is an invalid regular expression.

Examples

# Find match of regular expression in string
# Returns `[{"index":0,"match":"Hello"},{"index":5,"match":"World"}]`
- returnStep:
    return: ${text.find_all_regex("HelloWorld", "Hello|World")}