aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/contrib/nat/test_regexp.c
blob: 808a703ca6b10fba2d033bed018dc16fd2708095 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* make test_regexp */
#include <sys/types.h>
#include <regex.h>
#include <stdio.h>


int main(int argc, char **argv)
{
	regex_t reg;
	regmatch_t matches[2];

	if (argc != 4) {
		printf("Invoke with: test_regexp REGEXP REPLACE NR\n");
		return -1;
	}

	if (regcomp(&reg, argv[1], REG_EXTENDED) != 0) {
		fprintf(stderr, "Regexp '%s' is not valid.\n", argv[1]);
		return -1;
	}

	if (regexec(&reg, argv[3], 2, matches, 0) == 0 && matches[1].rm_eo != -1)
		printf("New Number: %s%s\n", argv[2], &argv[3][matches[1].rm_so]);
	else
		printf("No match.\n");

	regfree(&reg);

	return 0;
}