hanickadot / compile-time-regular-expressions

Compile Time Regular Expression in C++
https://twitter.com/hankadusikova
Apache License 2.0
3.36k stars 186 forks source link

Regex with [-+] fails to compile. #315

Closed EshwaryForReasons closed 3 months ago

EshwaryForReasons commented 3 months ago

I am trying to compile the following regex:

Regex: ([-+]?\d{4})
static constexpr ctll::fixed_string ctll_pattern = { R"(([-+]?\d{4}))" };

This failes to compile with the following error: use of undefined type 'ctre::problem_at_position<2>'. When using the same regex on regex101.com and regexr.com, it works fine. This seems to be common with + and - in a regex pattern, I cannot locate a consistent pattern, though.

hanickadot commented 3 months ago

CTRE is using different type of parser and grammar (it's mostly PCRE compatible, but there are deviations) you need to escape the minus: ([\-+]?\d{4}) as minus has a role in character class definition as defining range.

EshwaryForReasons commented 3 months ago

I see, my apologies! I thought I could transfer some regex over. I'll do a better job of reading the docs next time!