Match

Match — a convenience function that combines calls to Compile, Study, and Exec.

Synopsis

static Regex.Match(pattern, subject, options?=0,
                   length?=-1, startoffset?=0)
    

Arguments

pattern

A string specifying the regular expression pattern.

subject

The subject string on which to apply the pattern. This may be either a string or a buffer. If the subject is a buffer it may contain NUL characters.

options

Option flags - a bitwise OR of zero or more of these flags:

PCRE_ANCHORED
PCRE_BSR_ANYCRLF
PCRE_BSR_UNICODE
PCRE_CASELESS
PCRE_DOLLAR_ENDONLY
PCRE_DOTALL
PCRE_DUPNAMES
PCRE_EXTENDED
PCRE_EXTRA
PCRE_FIRSTLINE
PCRE_JAVASCRIPT_COMPAT
PCRE_MULTILINE
PCRE_NEWLINE_ANY
PCRE_NEWLINE_ANYCRLF
PCRE_NEWLINE_CR
PCRE_NEWLINE_CRLF
PCRE_NEWLINE_LF
PCRE_NOTBOL
PCRE_NOTEMPTY
PCRE_NOTEMPTY_ATSTART
PCRE_NOTEOL
PCRE_NO_AUTO_CAPTURE
PCRE_NO_START_OPTIMIZE
PCRE_NO_UTF8_CHECK
PCRE_PARTIAL_HARD
PCRE_PARTIAL_SOFT
PCRE_UNGREEDY
PCRE_UTF8
length

The length of the subject, in bytes. If length is -1 (the default), the length of the subject string is computed automatically.

startoffset

A byte offset into the subject specifying at which point to start.

Returns

On success, an array of match specifications equivalent to the substrings argument to Regex.Exec. On failure, an error list with three elements:

  • car(errlist) = a numeric return code from the failing function

  • cadr(errlist) = a character position in the pattern where the error occurred, or 0.

  • caddr(errlist) = an error message, as a human-readable string

Examples

Find and return all matches of hello, case sensitive:

Gamma> Regex.Match ("(hello)", "I say Hello and you say Goodbye");
(-1 0 "No match found")

Find and return all matches of hello, case insensitive:

Gamma> Regex.Match ("(hello)", "I say Hello and you say Goodbye",
PCRE_CASELESS);
[[0 31 #{I say Hello and you say Goodbye}] [6 11 #{Hello}]]

See Also

Compile, Study, Exec, and Subst