Skip to main content

regexp2.search(comparisonString, startIndex)

Finds the first sub-string within the passed string which matches the target regular expression

Availability

Agent

Parameters

Name Type Description
comparisonString String A string against which the regular expression is matched
startIndex Integer An optional index with the string at which to start matching

Returns

Table — the first match

Description

This method compares the target regular expression against the characters comprising the passed string and returns a table whose keys indicate the location of the first sub-string whose characters match the regular expression.

The table contains just two keys, begin and end, whose values are the indexes delimiting the matched sub-string within the source string. If there is no match, search() returns null.

A second, optional parameter may be passed to the method: the index within the passed string at which to begin the search for pattern matches. If this parameter is not provided, the search commences at the start of the string.

Example Code