If I use a saved substring it should capture the maximum number of characters that fit the pattern, in this case [0-9][0-9]*. echo "I'm 2254 years old"|sed "s/^..*\([0-9][0-9]*\) /She's \1 /" She's 4 years old" She should be 2254 years old. It does search correctly because without the substring it replaces all the digits: echo "I'm 2287 years old"|sed "s/^..*[0-9][0-9]*/She's many/" She's many years old" Here is my version information: sed --version # On Windows 10 sed (GNU sed) 4.4 Copyright (C) 2017 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later . This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Written by Jay Fenlason, Tom Lord, Ken Pizzini, and Paolo Bonzini. GNU sed home page: . General help using GNU software: . E-mail bug reports to: .