 <p>You don't replace the whole string with <code>\0</code>, just the pattern match, which is <code>This</code>. In other words, you replace <code>This</code> with <code>This</code>.</p> <p>To replace the whole line with <code>This</code>, you can do:</p> <pre><code>echo "This is a test string" | sed '/This/s/.*/This/' </code></pre> <p>It looks for a line matching <code>This</code>, and replaces the whole line with <code>This</code>. In this case (since there is only one line) you can also do:</p> <pre><code>echo "This is a test string" | sed 's/.*/This/' </code></pre> <p>If you want to reuse the match, then you can do</p> <pre><code>echo "This is a test string" | sed 's/.*\(This\).*/\1/' </code></pre> <p><code>\(</code> and <code>\)</code> are used to remember the match inside them. It can be referenced as <code>\1</code> (if you have more than one pair of <code>\(</code> and <code>\)</code>, then you can also use <code>\2</code>, <code>\3</code>, ...).</p> <p>In the example above this is not very helpful, since we know that inside <code>\(</code> and <code>\)</code> is the word <code>This</code>, but if we have a regex inside the parentheses that can match different words, this can be very helpful.</p>