I'm trying to use regexec with the [A-Za-z0-9_-] pattern but it seems not working. For instance "AZaz09%" contains illegal character '%' but surprisingly the match is OK and the found substring size is always (int)pm.rm_eo - (int)pm.rm_so = 1 insted of 6. Does anybody know what I'm doing wrong?
#include <stdio.h>
#include <regex.h>
int main()
{
char *string = "AZaz09%";
char *pattern = "[A-Za-z0-9_-]";
regex_t reg;
int match = REG_NOMATCH;
if (regcomp(®, pattern, 0) == 0)
{
regmatch_t pm;
match = regexec(®, string, 1, &pm, 0);
printf("%d\n",(int)pm.rm_eo - (int)pm.rm_so);
}
regfree(®);
if (match != REG_NOMATCH)
{
printf("OK");
}
else
{
printf("NOK");
}
return 0;
}