For example, I'm trying to parse a simple log message such as the below:
If I use the following code the regex parses OK and I'm able to extract the Log level from the rest of the message:I (1460) ipb_lfs: Initializing LittleFS
Code: Select all
const char *regex_pattern = "([IDWE]) (.+)";
regex_t regex;
int ret = regcomp(®ex, regex_pattern, REG_EXTENDED);
if (ret != 0)
{
printf("Failed to compile regex\n");
return -1;
}
regmatch_t matches[3];
ret = regexec(®ex, clean_message, 3, matches, 0)
Code: Select all
const char *regex_pattern = "([IDWE]) (\\S+) (.+)";
It seems the problem is linked to the inclusion of any escape characters.
Any suggestions how to solve this?