Description |
The behavior of the expr ':' operator when its pattern operand contains a BRE subexpression is described on page 2895, lines 96620-96623:Alternatively, if the pattern contains at least one regular expression subexpression "[\(...\)]", the string matched by the back-reference expression "\1" shall be returned. If the back-reference expression "\1" does not match, then the null string shell be returned. This implies that subexpressions include or must be enclosed between '[' and ']'. However, as per XBD Section 9.3.5, '[' introduces a bracket expression, within which a subexpression cannot occur (since "\(" is not treated specially).
This is the corresponding text from Commands and Utilities, Issue 5, page 337:Alternatively, if the pattern contains at least one regular expression subexpression [\(...\)], the string corresponding to \1 will be returned. It seems clear that '[' and ']' were being used in a parenthetical, not literal, capacity, but Issue 6 (https://pubs.opengroup.org/onlinepubs/009695399/utilities/expr.html) [^] missed that and simply wrapped the whole thing in quotation marks. It's been wrong ever since. |