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

Syntax error on lookbehind expression

Open pwuertz opened this issue 5 years ago • 2 comments
trafficstars

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.

pwuertz avatar Jul 30 '20 10:07 pwuertz

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

hanickadot avatar Jul 30 '20 11:07 hanickadot

@hanickadot Any progress/alternatives?

oijdfdg avatar Apr 30 '22 19:04 oijdfdg