The current man page says: "Finally, certain named classes of characters are predefined within bracket expressions, as follows. Their names are self explanatory, and they are [:alnum:], [:alpha:], [:blank:], [:cntrl:], [:digit:], [:graph:], [:lower:], [:print:], [:punct:], [:space:], [:upper:], and [:xdigit:]."
Whilst it may be self-explanatory to almost all grep users, it's not very helpful to dumb people like me. In fact, it just reinforces the fact. https://www.gnu.org/software/grep/manual/html_node/Character-Classes-and-Bracket-Expressions.html provides a helpful reference to explaining the character classes. Since most people (like me) consult the man page before turning to the manual (especially during an Internet disconnect or when impatient), I grafted the manual sections into the man page and came up with this patch: diff --git a/doc/grep.in.1 b/doc/grep.in.1 index 0a04be4..7a974ca 100644 --- a/doc/grep.in.1 +++ b/doc/grep.in.1 @@ -830,35 +830,85 @@ you can use the C locale by setting the environment variable to the value .BR C . .PP -Finally, certain named classes of characters are predefined within -bracket expressions, as follows. -Their names are self explanatory, and they are -.BR [:alnum:] , -.BR [:alpha:] , -.BR [:blank:] , -.BR [:cntrl:] , -.BR [:digit:] , -.BR [:graph:] , -.BR [:lower:] , -.BR [:print:] , -.BR [:punct:] , -.BR [:space:] , -.BR [:upper:] , +Finally, these character classes are predefined within bracket expressions +(all ASCII numbers are octal and reference the +.B 'C' +locale): +.TP +.B [:alnum:] +The combination of +.B [:alpha:] and -.BR [:xdigit:] . -For example, -.B [[:alnum:]] -means the character class of numbers and -letters in the current locale. -In the C locale and ASCII -character set encoding, this is the same as -.BR [0\-9A\-Za\-z] . -(Note that the brackets in these class names are part of the symbolic -names, and must be included in addition to the brackets delimiting -the bracket expression.) +.BR [:digit:] . +.TP +.B [:alpha:] +The combination of +.B [:lower:] +and +.BR [:upper:] . +.TP +.B [:blank:] +Space (040) and tab +.RB ( \et +or 011) characters. +.TP +.B [:cntrl:] +Control characters 000 to 037 and 177. +.TP +.B [:digit:] +Digits +.B [0\-9] +.RB ( \ed +or 060 through 071). +.TP +.B [:graph:] +The set of +.BR [:alnum:] and +.BR [:punct:] . +.TP +.B [:lower:] +Lowercase letters +.B [a\-z] +(141 to 172). +.TP +.B [:print:] +The combination of +.B [:graph:] +and space (040). +.TP +.B [:punct:] +Punctuation corresponding to 041 to 057, 072 to 100, 133 to 140, and +173 to 176. +.TP +.B [:space:] +Tab +.RB ( \et ), +newline +.RB ( \en ), +vertical tab +.RB ( \ev ), +form feed +.RB ( \ef ), +return +.RB ( \er ), +and space (011 to 015 and 040). +.TP +.B [:upper:] +Uppercase characters +.B [A\-Z] +(101 to 132). +.TP +.B [:xdigit:] +Hexadecimal numbers +.RB ( [0\-9A\-Za\-z] ). +.PP +(Note that the square brackets in these class names are part of the symbolic +names, and must be included with square brackets delimiting the character +class. +.PP Most meta-characters lose their special meaning inside bracket expressions. To include a literal -.B ] +.BR ] , place it first in the list. Similarly, to include a literal .B ^ @@ -866,6 +916,8 @@ place it anywhere but first. Finally, to include a literal .B \- place it last. +A character class combining all three would look like +.BR [] .\|.\|. ^ .\|.\|. -] . .SS Anchoring The caret .B ^ For which I neither have the credentials nor competence to add as a pull request. I'm sure my coding is atrocious. It took me a few hours with an AI bot to get even this far. Point being I encourage editorial changes or overhauls. If anything is inaccurate, then it's all the more reason to edit the man page. I'm largely following the manual, which I find helpful, and mapping it to my regex learning from way back. I hope it will reconcile grep's differences to the commonly used regex. It would still be very helpful to people like me if this can be fixed and patched. Thank you.
