rendered paste body#include <regex.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
int
main (int argc, char **argv)
{
int i, j;
int status;
regex_t regex;
regmatch_t *regmatch;
status = regcomp (®ex, ".*((\\.[0-9])?)\\.tar\\.bz2", REG_EXTENDED);
assert (status == EXIT_SUCCESS);
regmatch = calloc (regex.re_nsub, sizeof (regmatch_t));
for (j = 1; argv[j]; j++)
if (regexec (®ex, argv[j], regex.re_nsub, regmatch, 0) == EXIT_SUCCESS)
for (i = 0; i < regex.re_nsub; i++)
{
int start = regmatch[i].rm_so;
int end = regmatch[i].rm_eo;
if (start >= 0 && end >= 0)
{
char *str = argv[j];
int size = end - start;
char *cp = calloc (size + 1, sizeof (char));
strncpy (cp, &str[start], size);
cp[size] = 0;
printf ("%i: %s (%i)\n", j, cp, size);
free (cp);
}
}
free (regmatch);
regfree (®ex);
return 0;
}