I have a string similar to ../../sdd1 and trying to match sdd from here. I'm trying to use the following sed command:
echo "../../sdd1" | sed 's:.*\([a-z]\{3\}\)[0-9]?:\1:'
and it does not produce a match.
But when I use
echo "../../sdd1" | sed 's:.*\([a-z]\{3\}\)[0-9]\{0,1\}:\1:'
then I get my match, sdd.
My best guess is that I should escape the ? as well, similar to the curly brackets - I tried it and it works, but I don't know why.
So the question is, why does the [0-9]? regex not match the 1 from sdd1, or why do we have to escape the ? and the curly brackets?
-Eswitch, as well as the POSIX definitions of basic and extended regular expressions – Fox Jul 06 '17 at 08:19grephas the same flags/usage. – magor Jul 06 '17 at 08:32