Por padrão, sed
usa o BRE e precisa da opção -E
ou -r
para usar o ERE
Citações de manual do GNU sed
In GNU sed the only difference between basic and extended regular expressions is in the behavior of a few special characters: ‘?’, ‘+’, parentheses, braces (‘{}’), and ‘|’.
With basic (BRE) syntax, these characters do not have special meaning unless prefixed backslash (‘\’); While with extended (ERE) syntax it is reversed: these characters are special unless they are prefixed with backslash (‘\’).
então, para GNU sed
, use
$ echo '../../sdd1' | sed 's:.*\([a-z]\{3\}\)[0-9]\?::'
sdd
$ echo '../../sdd1' | sed -E 's:.*([a-z]{3})[0-9]?::'
sdd
para POSIX BRE , seu segundo comando é o caminho a seguir
$ echo '../../sdd1' | sed 's:.*\([a-z]\{3\}\)[0-9]\{0,1\}::'
sdd