capture-bounds ( group match -- from/f to/f )
Regular expressions ยป Regular expression capture groups

Prev:capture ( group match -- slice/f )
Next:regexp-match


Vocabulary
regexp

Inputs
groupa group number or name
matcha regexp-match


Outputs
from/fan integer or f
to/fan integer or f


Word description
Returns the zero-based start and exclusive end character indices of a capture in the original input. Group zero gives the whole match bounds. An unmatched group returns two f values; an empty capture returns two equal indices.

Errors
Throws unknown-capture-group for an unknown group.

Examples
USING: arrays kernel prettyprint regexp sequences ; "abcdefghijklmnopqrstuvwxyz" dup append R/ (abc)/ all-matches-with-captures [ 1 swap capture-bounds 2array ] map .
{ { 0 3 } { 26 29 } }


Definition