I need to include in my C code a POSIX ERE regex compiler/executer. I settled on the native regex.h library with something that looks like the following:
#include <regex.h>
bool
match_posix_regex(const char *pattern, const char *str){
regex_t regex;
int reti;
reti = regcomp(®ex, pattern, REG_EXTENDED);
if(reti){
printf("Could not compile the regex\n");
return false;
}
reti = regexec(®ex, str, 0, NULL, 0);
if(!reti){
return true;
}
else if (reti == REG_NOMATCH){
return false;
}
else{
printf("ERROR in regex execution\n");
return false;
}
}
It came to my attention that this implementation includes support for back-referencing. It is my understanding that POSIX ERE standards do not support back-referencing, however many implementations of these standards do. Looking at the regex.h docs it doesn't seem like I'll be able to disable this feature.
I do not want to include support for back-referencing as it is not included in the standards and furthermore it can result in catastrophic backtracking as described here.
Is there a way I can compile and run a regex in C that is compliant with POSIX ERE standards and does not include back-referencing as a feature?