As others have already pointed out, it is clear that POSIX ERE does not support backlinks.
The rationale given in the basic specifications of OpenGroup Issue 7 for not adding backreferences to the ERE is given as:
It has been suggested that in addition to interval expressions, backreferences ('\ n') should also be added to the ERE. This has been rejected by standard developers as they can reduce consensus.
Quote from: Justification: Basic Definitions: Extended Regular Expressions
The main reason for this restriction is to allow the conversion of POSIX EES to deterministic finite state machines (DFAs), and indeed, the initial implementation of ERE on Unix was done as a DFA. Using DFA allows you to guarantee performance. Matching patterns with (unlimited) backlinks is an NP-hard problem and possibly even an NP-complete problem. Consensus in the POSIX standards committee would never have been achieved if ERE backlinks were proposed, because it would force all companies using the original Unix implementation to change their code to a non-deterministic implementation and abandon their performance guarantees, and some of these The companies were members of the committee.
It was also noted that backlinks in RE are not intuitive for either users or developers, and indeed, they caused extreme confusion more often than now. See, for example, the examples given in RE-Interpretation: The Dark Corners
NOTE. backlinks in REs do not match subpattern references in lookup text in tools like sed.
Greg A. Woods
source share