echo 'text[2*?!]'|sed 's/\(text\)\(\[[2-4]\)/vinay\2/'
searces for an exact match for text
searches for a litteral [
character followed by a number between 2
refers to text
(but we are not using this part.
refers (in this instance) to [2
We replace the search with vinay followed by the second reference [2 the rest of the string is kept as it wasn't part of the search.