blob: 808a703ca6b10fba2d033bed018dc16fd2708095 [file] [log] [blame]
Holger Hans Peter Freyther384ef092011-05-24 15:56:14 +02001/* make test_regexp */
2#include <sys/types.h>
3#include <regex.h>
4#include <stdio.h>
5
6
7int main(int argc, char **argv)
8{
9 regex_t reg;
10 regmatch_t matches[2];
11
12 if (argc != 4) {
13 printf("Invoke with: test_regexp REGEXP REPLACE NR\n");
14 return -1;
15 }
16
17 if (regcomp(&reg, argv[1], REG_EXTENDED) != 0) {
18 fprintf(stderr, "Regexp '%s' is not valid.\n", argv[1]);
19 return -1;
20 }
21
22 if (regexec(&reg, argv[3], 2, matches, 0) == 0 && matches[1].rm_eo != -1)
23 printf("New Number: %s%s\n", argv[2], &argv[3][matches[1].rm_so]);
24 else
25 printf("No match.\n");
26
27 regfree(&reg);
28
29 return 0;
30}