summaryrefslogtreecommitdiffhomepage
path: root/docs/cregex_api.md
diff options
context:
space:
mode:
authorTyge Lovset <[email protected]>2023-05-20 07:24:22 +0200
committerTyge Lovset <[email protected]>2023-05-20 07:24:22 +0200
commited9ccf1dcca8d3651e13ff1686148b4b23773721 (patch)
tree0594df357a1b4239a0d38c686099242cc16b0b44 /docs/cregex_api.md
parent26513bb1352ab4e4ffe931aabd80868216afc551 (diff)
downloadSTC-modified-ed9ccf1dcca8d3651e13ff1686148b4b23773721.tar.gz
STC-modified-ed9ccf1dcca8d3651e13ff1686148b4b23773721.zip
Bug fix (NB!): cregex_captures() now returns num of cap. group *excluding* the full match group (0).
Diffstat (limited to 'docs/cregex_api.md')
-rw-r--r--docs/cregex_api.md10
1 files changed, 5 insertions, 5 deletions
diff --git a/docs/cregex_api.md b/docs/cregex_api.md
index 9a15a869..e702c47c 100644
--- a/docs/cregex_api.md
+++ b/docs/cregex_api.md
@@ -29,7 +29,7 @@ cregex cregex_from(const char* pattern, int cflags = CREG_DEFAULT);
// return CREG_OK, or negative error code on failure
int cregex_compile(cregex *self, const char* pattern, int cflags = CREG_DEFAULT);
- // num. of capture groups in regex. 0 if RE is invalid. First group is the full match
+ // num. of capture groups in regex, excluding the 0th group which is the full match
int cregex_captures(const cregex* self);
// return CREG_OK, CREG_NOMATCH, or CREG_MATCHERROR
@@ -139,14 +139,14 @@ To iterate multiple matches in an input string, you may use
```c
csview match[5] = {0};
while (cregex_find(&re, input, match, CREG_M_NEXT) == CREG_OK)
- c_forrange (k, cregex_captures(&re))
- printf("submatch %lld: %.*s\n", k, c_SV(match[k]));
+ for (int k = 1; i <= cregex_captures(&re); ++k)
+ printf("submatch %d: %.*s\n", k, c_SV(match[k]));
```
There is also a for-loop macro to simplify it:
```c
c_formatch (it, &re, input)
- c_forrange (k, cregex_captures(&re))
- printf("submatch %lld: %.*s\n", k, c_SV(it.match[k]));
+ for (int k = 1; i <= cregex_captures(&re); ++k)
+ printf("submatch %d: %.*s\n", k, c_SV(it.match[k]));
```
## Using cregex in a project