Handbook
Glossary
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
group
a group number or name
match
a
regexp-match
Outputs
slice/f
a
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
USING:
accessors
assocs
kernel
math
regexp.captures
sequences
strings
;
IN:
regexp
::
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
;