regex/capture
capture-count
(capture-count [match : Match] :)
number of captured substrings in a Match.
| match | Match handle from regex-match |
:int -- number of captured groups (0 = only full match in group 0)
(capture-count m) ; => 2
Since: P6 (typed in 0.2.0)
capture-at
(capture-at [match : Match idx : int] :)
substring captured by a numbered group.
| match | Match handle from regex-match | |
| idx | group index (0 = full match, 1 = first capture group, ...) |
:cstr -- captured substring as a freshly malloc'd copy the caller frees; a malloc'd empty string "" when the group did not participate or the index is out of range. (Prior to 0.3.0 the empty case returned a static "" literal, so a caller that freed the result per this contract crashed on empty groups -- that footgun is fixed: the return is now uniformly owned. Prefer capture-at-string for an owned String that cannot be forgotten.)
(capture-at m 0) ; full match (capture-at m 1) ; first capture group
Since: P6 (typed in 0.2.0; uniformly-owned empty case in 0.3.0)
capture-named
(capture-named [match : Match name : cstr] :)
substring captured by a named group.
| match | Match handle from regex-match | |
| name | group name as it appears in the pattern (e.g. "year") |
:cstr -- captured substring as a freshly malloc'd copy the caller frees; a malloc'd empty string "" when the group is not found / did not participate. (Uniformly owned since 0.3.0 -- see capture-at.) Prefer capture-named-string for an owned String.
(capture-named m "year")
Since: P6 (typed in 0.2.0; uniformly-owned empty case in 0.3.0)
capture-at-string
(capture-at-string [match : Match idx : int] :)
owned-String sibling of capture-at.
| match | Match handle from regex-match | |
| idx | group index (0 = full match, 1 = first capture group, ...) |
String -- owned captured substring.
(capture-at-string m 1) ; owned first capture group
Since: 0.3.0
capture-named-string
(capture-named-string [match : Match name : cstr] :)
owned-String sibling of capture-named.
| match | Match handle from regex-match | |
| name | group name as it appears in the pattern (e.g. "year") |
String -- owned captured substring.
(capture-named-string m "year") ; owned named capture
Since: 0.3.0