Holger Hans Peter Freyther | 384ef09 | 2011-05-24 15:56:14 +0200 | [diff] [blame] | 1 | /* make test_regexp */ |
| 2 | #include <sys/types.h> |
| 3 | #include <regex.h> |
| 4 | #include <stdio.h> |
| 5 | |
| 6 | |
| 7 | int 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(®, argv[1], REG_EXTENDED) != 0) { |
| 18 | fprintf(stderr, "Regexp '%s' is not valid.\n", argv[1]); |
| 19 | return -1; |
| 20 | } |
| 21 | |
| 22 | if (regexec(®, 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(®); |
| 28 | |
| 29 | return 0; |
| 30 | } |