UCE Docs / regex_search

Signature

DValue regex_search(String pattern, String subject)
DValue regex_search(String pattern, String subject, String flags)

Parameters

pattern : PCRE2 regular expression pattern
subject : string to search
flags : optional regex flags
return value : a DValue describing the first match

Searches subject for the first occurrence of pattern and returns structured match data.

Example:

Return shape:

  • matched is a boolean.

  • pattern stores the original pattern.

  • flags stores the supplied flags, or default.

  • match is the full matched text when a match exists.

  • start and end are byte offsets into the original string.

  • captures is a list of capture objects, with capture 0 representing the full match.

  • named maps named capture groups to their captured text.

  • named_offsets maps named capture groups to index, start, and end metadata.

Capture entries contain:

If no match is found, matched is false and match-specific fields are omitted.

Example

DValue match = regex_search("docs", "uce docs");
print(match["match"].to_string(), "\n");
Output
docs