Handbook
Glossary
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
group
a group number or name
match
a
regexp-match
Outputs
from/f
an
integer
or
f
to/f
an
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
USING:
accessors
kernel
;
IN:
regexp
:
capture-bounds
( group match -- from/f to/f )
capture
[
[
from>>
]
[
to>>
]
bi
]
[
f
f
]
if*
;