#include <regex.h>
const char *data1 = "aaab";
const char *data2 = "aaaba";
const char *data3 = "bbba";
//REG_NOSUB: only yes or no, without the match positions
regex_t regex;
if (regcomp(®ex, "a+b", REG_EXTENDED | REG_NOSUB) != 0) {
exit(EXIT_FAILURE);
}
//regexec returns 0 when the pattern is found anywhere
bool b1 = regexec(®ex, data1, 0, nullptr, 0) == 0;
//b1 is true
bool b2 = regexec(®ex, data2, 0, nullptr, 0) == 0;
//b2 is true
bool b3 = regexec(®ex, data3, 0, nullptr, 0) == 0;
//b3 is false
regfree(®ex);
printf("b1 is %s\n", b1 ? "true" : "false");
printf("b2 is %s\n", b2 ? "true" : "false");
printf("b3 is %s\n", b3 ? "true" : "false");