Im trying to understand what expressions exactly the regular expression (^[0-9]..[a-zA-Z ]+$)
detects in grep
command (linux terminal)
I know that if I'd write the following command:
grep ^[0-9]..[a-zA-Z] filename.txt
I will detect any line that contains expressions such as 92afg
But Im not sure what the +$
means and what kind of expressions will I be able to detect with the command
grep ^[0-9]..[a-zA-Z]+$ filename.txt
I tried to open a new text file and just type expressions that I thought would be detected, but none of them matched, so I'd appreciate explanation for this.
^
), but still... – Kusalananda Nov 03 '21 at 10:58zsh
andbash -O failglob
. Also fish (though[...]
is not a glob operator there), csh, tcsh and pre-Bourne shells.nullglob
would also be a problem in the shells that have it.^
is also special in many shells. – Stéphane Chazelas Nov 03 '21 at 10:59+
that makes this require-E
for Extended Regular Expressions (ERE) - the rest of the regex works the same in either BRE or ERE. Some, but by no means all, Basic Regular Expression (BRE) engines allow you to backslash-escape a+
as\+
to make it mean "one-or-more" like in an ERE rather than a literal+
character. – cas Nov 03 '21 at 11:33[0-9]
or[a-zA-Z]
matches a single character though which remains potentially misleading (especially if that's intended as input sanitisation). – Stéphane Chazelas Nov 03 '21 at 14:27