Implements the OP_PCRE2_FINDALL opcode (conditional build).
Finds all non-overlapping matches of a PCRE2 pattern in a subject string and returns an array of maps describing each match when FUN_WITH_PCRE2 is enabled. When PCRE2 support is disabled at build time, the opcode falls back to returning an empty array.
Definition in file findall.c.
OP_PCRE2_FINDALL: (pattern:any, text:any, flags:int|bool=0) -> array(map)
Behavior when FUN_WITH_PCRE2 is enabled:
- Pops three arguments from the VM stack: pattern, text, flags.
- pattern and text are converted to strings using value_to_string_alloc().
- flags bits map to PCRE2 options:
- 1 = PCRE2_CASELESS (I)
- 2 = PCRE2_MULTILINE (M)
- 4 = PCRE2_DOTALL (S)
- 8 = PCRE2_UTF (U)
- 16 = PCRE2_EXTENDED (X)
- Compiles the pattern and scans the subject for all non-overlapping matches. For each match, pushes into the result array a map with keys:
- "full": matched substring (group 0)
- "start": start index (int)
- "end": end index (int, exclusive)
- "groups": array of captured group strings (excluding group 0)
- On compilation error or allocation failure, returns an empty array.
Behavior when FUN_WITH_PCRE2 is disabled:
- Pops three values and returns an empty array.
Definition at line 45 of file findall.c.