.TE
.SH CONFORMING TO
POSIX.1-2001, POSIX.1-2008.
+.SH EXAMPLES
+.EX
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <regex.h>
+
+#define ARRAY_SIZE(arr) (sizeof((arr)) / sizeof((arr)[0]))
+
+static const char *const str =
+ "1) John Driverhacker;\en2) John Doe;\en3) John Foo;\en";
+static const char *const re = "John.*o";
+
+int main(void)
+{
+ static const char *s = str;
+ regex_t regex;
+ regmatch_t pmatch[1];
+ regoff_t off, len;
+
+ if (regcomp(®ex, re, REG_NEWLINE))
+ exit(EXIT_FAILURE);
+
+ printf("String = \e"%s\e"\en", str);
+ printf("Matches:\en");
+
+ for (int i = 0; ; i++) {
+ if (regexec(®ex, s, ARRAY_SIZE(pmatch), pmatch, 0))
+ break;
+
+ off = pmatch[0].rm_so + (s \- str);
+ len = pmatch[0].rm_eo \- pmatch[0].rm_so;
+ printf("#%d:\en", i);
+ printf("offset = %jd; length = %jd\en", (intmax_t) off, (intmax_t) len);
+ printf("substring = \e"%.*s\e"\en", len, s + pmatch[0].rm_so);
+
+ s += pmatch[0].rm_eo;
+ }
+
+ exit(EXIT_SUCCESS);
+}
+.EE
.SH SEE ALSO
.BR grep (1),
.BR regex (7)