2 ms·
I might actually like something like this if it did not try to replace conventional regex syntax but aimed at making it more useful by enabling composition of
by usrusr 6y ago
I might actually like something like this if it did not try to replace conventional regex syntax but aimed at making it more useful by enabling composition of smaller blocks of (conventional) regex into larger. An API like that could certainly also have an equivalent of Pattern.quote(..) for the few times what you actually do want to enter unescaped (ever tried reading regex with regex?), but it would just be a minor nice to have feature.
It wouldn't even have to contain all the small blocks (like [] single char alternatives, those are best left as is), just an option to describe bigger round-brace blocks out in the java syntax where nesting is validated in compile. Lookahead, lookbehind, their negatives, capture, noncapture. Noncapture with a varargs (or builder) API of piped alternatives.
You could still provoke a PatternSyntaxException by writing invalid stuff in the conventional blocks, but if the composed pattern fails checking the subpatterns should be quite helpful (if there are no backreferences)