3 ms·
The POSIX standard for regular expressions (which grep implemented half a century ago) doesn't support back references. Even I-Regexp (RFC 9485) doesn't suppor
by shagie 2y ago
The POSIX standard for regular expressions (which grep implemented half a century ago) doesn't support back references. Even I-Regexp (RFC 9485) doesn't support it.
This specification describes an interoperable regular expression (abbreviated as "regexp") flavor, I-Regexp.
I-Regexp does not provide advanced regular expression features such as capture groups, lookahead, or backreferences. It supports only a Boolean matching capability, i.e., testing whether a given regular expression matches a given piece of text.
It wasn't until '97 when PCRE was released to mimic Perl's handling of regex and some time after that that GNU grep added -P as an option (BSD doesn't appear to support PCRE).
While PCRE is a defacto standard (I been heard uttering "ugh, that only handles posix regex"), for most of the history of regex they were only as powerful as a NDFA.
- fanf2 2y agoPOSIX BREs do support backrefs. See section 9.3.6 BREs Matching Multiple Characters point 3 at https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/V1_chap09.html#tag_09_03 https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/V1... Backref support was added to grep between 6th edition and 7th edition unix 6th edition grep manual: http://man.cat-v.org/unix-6th/1/grep http://man.cat-v.org/unix-6th/1/grep 7th edition grep manual: http://man.cat-v.org/unix_7th/1/grep http://man.cat-v.org/unix_7th/1/grep Both of those refer to ed(1) for the syntax of regular expressions 6th edition ed manual: http://man.cat-v.org/unix-6th/1/ed http://man.cat-v.org/unix-6th/1/ed 7th edition ed manual: http://man.cat-v.org/unix_7th/1/ed http://man.cat-v.org/unix_7th/1/ed POSIX EREs do not support backrefs. This goes back to the 1970s because egrep used a different regex matching algorithm to grep — egrep compiled the regex to a DFA which could not match backrefs, unlike grep’s nondeterministic algorithm — and egrep also had different syntax.