I am trying to grep for any string that matches the following:
AAA-###
Where A is any alpha character, and there can be from 2 to 5 of them.
# is any digit, and there could be 1 or more of them.
So, the following strings should be found:
ABC-123
DE-4
FGHI-56789
But this shouldn’t be found:
A15-B432
I tried a few different things, like this:
grep [[:alpha:]]\{2,5\}-[[:digit:]]\+
However, that didn’t work.
This is gnu grep on redhat. In my testing, using grep on my windows machine, which was also using gnu grep, this worked. Both seem to be version 2.5.1.
You need the
-Eflag for extended regular expressions:I personally prefer to use
''to avoid all the\characters: