compile-time-regular-expressions icon indicating copy to clipboard operation
compile-time-regular-expressions copied to clipboard

look behind unimplemented

Open aaangeletakis opened this issue 3 years ago • 3 comments

The following regex fails to compile with the error:

"Regular Expression contains syntax error."

I suspect it has to due to the digit look behind in the floating-point literals rule.

R"([a-zA-Z]{0,2}?(("|')(\2{2})?)((?:[^\\"]|\\.|\\)*\1)?|)"  //capture strings - check later on if string
                                                            //                  prefix is valid and the string terminates
R"((#[^\r\n]*)|)"                                           //capture comments
R"(([\n\r][ \t]*)|)"                                        //capture newlines
R"((\\[^\r\n]*)|)"                                          //capture \TheBackslashAndAnythingAfterIt
R"(()"
    R"((\.{3})|)"                                           //capture ...
    R"((->)|)"
    R"((\d*(\.\d*)?)(?<=\d)(([eE]-?[\d_]*)|[\w]*)|)"        //floating point numbers
    R"(([<>*\/]{2})=?|)"                                    //capture 2-3 character operators
    R"(([!%&*+\-<=>@\/\\^|:]=))"                            //capture 2 caracter operators
R"()|)"
R"(([!-\/:-@\[-^{-~]|[^\s!-\/:-@\[-^{-~]+)|)"               //capture anything else
R"((\s+))"                                                  //capture whitespace in order to keep track of position with ctre

https://regex101.com/r/MkA1rH/1

aaangeletakis avatar Mar 02 '21 07:03 aaangeletakis

Please minimise the regex.

hanickadot avatar Mar 02 '21 08:03 hanickadot

Edit: The issue is the libary is mistaking (?<=\d) as a sytax error

(\d*(\.\d*)?)(?<=\d)

https://regex101.com/r/Aq4bit/1 example code:

#include <ctre.hpp>

int main(void){
    constexpr static ctll::fixed_string float_num = R"((\d*(\.\d*)?)(?<=\d))";
    return ctre::match<float_num>("1.1");
}

https://gcc.godbolt.org/z/7Wzcae

aaangeletakis avatar Mar 02 '21 18:03 aaangeletakis

Look behind positive nor negative is implemented.

hanickadot avatar Mar 02 '21 18:03 hanickadot