Support of "if" and "(?R)" in Regex

Why still no support for "if" and "(?R)" in Regex?

Hi @oleedd could you point to references from other languages that have these features? I'd be interested to hear what they are.

Hi. It is probably the most known and useful what JavaScript doesn't have.

  1. (?(condition)then|else). It is very old and seems to be not supported only in JavaScript.

  2. (?R) or (?0) tries to match the entire regex recursively. (?1), (?2), etc, try to match the relevant group.

(?&name) tries to match the named group.

regex.match(r"(Tarzan|Jane) loves (?1)", "Tarzan loves Jane").groups()
('Tarzan',)
regex.match(r"(Tarzan|Jane) loves (?1)", "Jane loves Tarzan").groups()
('Jane',)

m = regex.search(r"(\w)(?:(?R)|(\w?))\1", "kayak")
m.group(0, 1, 2)
('kayak', 'k', None)

The first two examples show how the subpattern within the group is reused, but is not itself a group. In other words, "(Tarzan|Jane) loves (?1)" is equivalent to "(Tarzan|Jane) loves (?:Tarzan|Jane)".

It’s possible to backtrack into a recursed or repeated group.

You can’t call a group if there is more than one group with that group name or group number ("ambiguous group reference").

The alternative forms (?P>name) and (?P&name) are also supported.

It is a very known solution to match closing parenthesis and what is inside. I don't think it is problematic to implement because the engine just replaces "(?R)" with the whole regex patern, it just becomes bigger. And on backtracking, it should not remove those replacements.

More interesting new features here: regex · PyPI

JavaScript regex syntax is based on Perl, and the Perl docs are also quite searchable.

Both of these are existing Perl features: https://perldoc.perl.org/perlre#(?(condition)yes-pattern|no-pattern), https://perldoc.perl.org/perlre#(?PARNO)-(?-PARNO)-(?+PARNO)-(?R)-(?0).

Because no one said about this? It is unlikely.
JavaScript regex seems to be the most backward. Why so?