Method Regexp.PCRE2._pcre()->exec()
classRegexp.PCRE2._pcre
- Method
exec
int|arrayexec(stringsubject,void|intstartoffset)- Description
Matches the regexp against
subject, starting atstartoffsetif it is given.If the match is successful, the return value is an array that holds the offsets of all matches:
Elements 0 and 1 have the start and end offsets, respectively, of the match for the whole regexp. The start offset is inclusive while the end is exclusive, i.e. the matching string is
.subject[res[0]..res[1]-1]Elements 2 and 3 have the offsets of the first capturing submatch (if any) in the same way, elements 4 and 5 are for the second capturing submatch, etc. If a submatch didn't match anything, the corresponding elements are set to -1. If a submatch has matched successfully several times, the offsets of the last match are returned.
The returned array is always of length 2*n + 1, where n is the total number of capturing submatches in the regexp.
If there is an error, an integer error code is returned:
ERROR.NOMATCHThe subject string did not match the pattern.
ERROR.NULLEither the code, subject, or match_data argument was passed as NULL.
ERROR.BADOPTIONAn unrecognized bit was set in the options argument.
ERROR.BADMAGICPCRE2 stores a 4-byte "magic number" at the start of the compiled code, to catch the case when it is passed a junk pointer. This is the error it gives when the magic number isn't present.
ERROR.NOMEMORYHeap memory is used to remember backtracking points. This error is given when the memory allocation function (default or custom) fails. Note that a different error, ERROR.HEAPLIMIT, is given if the amount of memory needed exceeds the heap limit.
ERROR.NOSUBSTRINGThis error is used by the pcre_copy_substring(), pcre_get_substring(), and pcre_get_substring_list() functions (see below). It is never returned by pcre_exec().
ERROR.MATCHLIMITThe recursion and backtracking limit, as specified by the match_limit field in a pcre_extra structure (or defaulted) was reached. See the description above.
ERROR.HEAPLIMITThe heap limit was reached.
ERROR.CALLOUTThis error is never generated by pcre_exec() itself. It is provided for use by callout functions that want to yield a distinctive error code. See the pcrecallout documentation for details.