hanickadot / compile-time-regular-expressions

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

Syntax error on lookbehind expression #105

Open pwuertz opened 4 years ago

pwuertz commented 4 years ago

CTRE doesn't seem to support lookbehind rules, like (?<=x) or (?<!x).

Compiler-explorer / GCC trunk reports a failed assertion in functions.hpp:

/opt/compiler-explorer/libs/ctre/master/include/ctre/functions.hpp:74:23: error:
   static assertion failed: Regular Expression contains syntax error.

Example:

#include <ctre.hpp>

constexpr bool a_not_preceded_by_b(const std::string_view s)
{
    constexpr auto pattern1 = ctll::fixed_string{ "[^b](?=a)" };  // Works
    constexpr auto pattern2 = ctll::fixed_string{ "(?<!b)a" };  // Fails
    return ctre::search<pattern2>(s);
}

static_assert(a_not_preceded_by_b("xa"));
static_assert(!a_not_preceded_by_b("ba"));

Is this a known issue? The lookahead expressions (?=x) and (?!x) seem to work though.

hanickadot commented 4 years ago

It's not implemented. If you want, send a PR.

oijdfdg commented 2 years ago

@hanickadot Any progress/alternatives?