regex/capture
src/regex/capture.tur
defn
capture-count
(capture-count [match :int] :int)
number of captured substrings in a match result.
Parameters
| match | :int match handle from regex-match |
Returns
:int -- number of captured groups (0 = only full match in group 0)
Example
(capture-count m) ; => 2
Since: P6
defn
capture-at
(capture-at [match :int idx :int] :cstr)
substring captured by a numbered group.
Parameters
| match | :int match handle from regex-match | |
| idx | group index (0 = full match, 1 = first capture group, ...) |
Returns
:cstr -- captured substring (malloc'd copy), or "" if group did not participate
Example
(capture-at m 0) ; full match (capture-at m 1) ; first capture group
Since: P6
defn
capture-named
(capture-named [match :int name :cstr] :cstr)
substring captured by a named group.
Parameters
| match | :int match handle from regex-match | |
| name | group name as it appears in the pattern (e.g. "year") |
Returns
:cstr -- captured substring (malloc'd copy), or "" if not found / did not participate
Example
(capture-named m "year")
Since: P6