I have the following regex:
(?<weekday>\w{3}),\s+(?<day>\d{1,2})\s+(?<month>\w{3})\s+(?<year>\d{4})\s+(?<hours>\d{2}):(?<minutes>\d{2}):(?<seconds>\d{2})\s+(?<timezone_offset>[+\-]\d{4})(?:\s+\((?<timezone_name>\w+)\))?
The goal is to match the following date:
Fri, 2 Aug 2024 18:02:15 -0000 (UTC)
The reason I am using regex is because it could be any of the following (basically anything in roughly that format):
Fri, 2 Aug 2024 18:02:15 -0000 (UTC)
Fri, 2 Aug 2024 18:02:15 +0000 (UTC)
Fri, 2 Aug 2024 18:02:15 0000 (UTC)
Fri, 2 Aug 2024 18:02:15 -0000 (UTC)
Fri, 2 Aug 2024 18:02:15 0000 (UTC)
Fri, 2 Aug 2024 18:02:15 -0000 (UTC)
Fri, 2 Aug 2024 18:02:15 -0000
...
Using regex101.com I can match them all just fine under the PCRE setting. Unfortunately, with the following ctre code the first match contains the whole string:
static constexpr ctll::fixed_string ctll_pattern = { R"((?<weekday>\w{3}),\s+(?<day>\d{1,2})\s+(?<month>\w{3})\s+(?<year>\d{4})\s+(?<hours>\d{2}):(?<minutes>\d{2}):(?<seconds>\d{2})\s+(?<timezone_offset>[+\-]\d{4})(?:\s+\((?<timezone_name>\w+)\))?)" };
static constexpr ctll::fixed_string ctll_weekday = "weekday";
static constexpr ctll::fixed_string ctll_day = "day";
static constexpr ctll::fixed_string ctll_month = "month";
static constexpr ctll::fixed_string ctll_year = "year";
static constexpr ctll::fixed_string ctll_hours = "hours";
static constexpr ctll::fixed_string ctll_minutes = "minutes";
static constexpr ctll::fixed_string ctll_seconds = "seconds";
static constexpr ctll::fixed_string ctll_timezone_offset = "timezone_offset";
static constexpr ctll::fixed_string ctll_timezone_name = "timezone_name";
std::string s_weekday, s_month, s_timezone_name;
int day = 0, year = 0, hours = 0, minutes = 0, seconds = 0, timezone_offset = 0;
const auto all_matches = ctre::multiline_search_all<ctll_pattern>("Fri, 2 Aug 2024 18:02:15 -0000 (UTC)");
for (const auto& match : all_matches)
{
std::cout << match.to_string() << "\n";
}
Is there some particular detail about CTRE which is stopping this from being matched? Unfortunately, I am rather new to regex so this is a quite hard to debug.
Bonus: any way to make this compile faster? Visual Studio 2022 MSVC 19.40 builds this is about 15 seconds in debug mode and ~30 min in release mode. This is unrelated though, but I figured someone may have some kind of knowledge here.