0
$\begingroup$

Reading the manual for GNU grep, the special characters (with -E option) are .?*+{|()[\^$.

This is a somewhat pedantic question, but why are ] and } omitted? In particular it says in section 3.1 "An unmatched ) just matches itself", which is true for ] and } as well.

I think it is just a slightly sleeker description of ERE–we can get by without } and ] being special, because their syntactic purpose is served only in a context where specialness fails to be meaningful (that is, after an unmatched { or [ has occurred).

Note that this is not a question about GNU grep per se, but rather about the syntactic rules of ERE.

$\endgroup$
2
  • $\begingroup$ My advice is not authoritative, but I would imagine that this spares useless escaping of these right delimiters. The Unix freaks loved compact typing. $\endgroup$
    – user16034
    Jun 9, 2023 at 9:24
  • $\begingroup$ Just a guess: One difference between () versus {} and [] is that () can be nested. If you have an unmatched ) within nested parentheses, you end up with an ambiguous expression. $\endgroup$ Jun 12, 2023 at 18:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.