Problem parsing Regex pattern with escape characters
Posted: Sat Nov 09, 2024 8:14 pm
I'm trying to use regex.h on an ESP32S3 in ESP-IDF 5.3.1 to extract elements from a log message so that I can reformat it to be IETF compliant. However, whenever I try to use a regex pattern including any escape characters, it fails.
For example, I'm trying to parse a simple log message such as the below:
However as soon as I change the regex pattern to something even slightly more complicated, such as:
It fails to parse the message.
It seems the problem is linked to the inclusion of any escape characters.
Any suggestions how to solve this?
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?