findall ( subject obj -- matches )
PCRE2 binding

Prev:<pcre2> ( expr -- pcre2 )
Next:matches? ( subject obj -- ? )


Vocabulary
pcre2

Inputs
subjecta string
obja string, compiled regular expression or a regexp literal


Outputs
matchesa sequence


Word description
Finds all matches of the given regexp in the string. Matches is a sequence of associative arrays, one per match, holding the full match followed by every capturing group in order. The key is the name of the capturing group, or f for the full match and for unnamed groups. A group that did not participate in the match is reported as an empty string.

Examples
USE: pcre2 "foobar" "(?<ch1>\\w)(?<ch2>\\w)" findall . { { { f "fo" } { "ch1" "f" } { "ch2" "o" } } { { f "ob" } { "ch1" "o" } { "ch2" "b" } } { { f "ar" } { "ch1" "a" } { "ch2" "r" } } }


Definition

GENERIC: findall ( subject obj -- matches )


Methods

M:: pcre2 findall ( subject obj -- matches )
[
subject utf8 encode
:> subject_bytes subject_bytes length :> subject_length
obj handle>> :> re re pcre2-utf? :> utf? re pcre2-crlf?
:> crlf? re f pcre2_match_data_create_from_pattern
&pcre2_match_data_free :> match_data 0 :> start_offset!
0 :> options! re subject_bytes subject_length
start_offset options match_data f pcre2_match
:> rc re pcre2-name-table-entries :> name_table rc 0 < [
rc
{ { PCRE2_ERROR_NOMATCH [ ~array~ ] } [ throw ] }
case
] [
rc assert-positive drop
match_data pcre2_get_ovector_pointer match_data
pcre2_get_ovector_count 2 *
PCRE2_SIZE <c-direct-array> :> ovector [
rc ovector name_table subject_bytes
subject_length parse-match , [
f :> break?! 0 options! ovector second
start_offset! ovector first2 = [
ovector first subject_length =
2147483656 options!
] [
match_data pcre2_get_startchar
:> startchar start_offset startchar <=
~quotation~ ~quotation~ if
] if
[ f ] [
re subject_bytes subject_length
start_offset options match_data f
pcre2_match
:> rc rc PCRE2_ERROR_NOMATCH =
~quotation~ ~quotation~ if
] if
] loop
] { } make
] if
] with-destructors ;