functionregex

Matches a string with a regular expression and returns the result.

Information

Sets the error buffer and returns -1 if the regex does not compile.

The returned result is the same as POSIX regex():

  • The first value is the complete matched string.
  • The rest are the substrings that you wanted.

For example:

regex(lorem," \([A-Za-z]*\) \([A-Za-z]*\) ",maxMatches=3)
  => {" ipsum dolor ","ipsum","dolor"}

This means if you have n groups, you want maxMatches=n+1.

Inputs

TypeNameDefaultDescription
Stringstr
Stringre
IntegermaxMatches1The maximum number of matches that will be returned
BooleanextendedtrueUse POSIX extended or regular syntax
BooleancaseInsensitivefalse

Outputs

TypeNameDefaultDescription
IntegernumMatches-1 is an error, 0 means no match, else returns a number 1..maxMatches
String[maxMatches]matchedSubstringsunmatched strings are returned as empty