capture ( group match -- slice/f )
Regular expressions ยป Regular expression capture groups

Prev:all-matches-with-captures ( string regexp -- matches )
Next:capture-bounds ( group match -- from/f to/f )


Vocabulary
regexp

Inputs
groupa group number or name
matcha regexp-match


Outputs
slice/fa slice or f


Word description
Returns a group by its zero-based number or string name. Group zero is the whole match. Returns f for a group that did not participate.

Errors
Throws unknown-capture-group if the group number or name does not exist.

Definition


:: capture ( group match -- slice/f )
group string? [
group match names>> at
[ group unknown-capture-group ] unless*
] [ group ] if :> index index integer?
[ index 0 >= index match groups>> length < and ] [ f ] if
[ index match groups>> nth ] [ group unknown-capture-group ]
if ;