<p>I would like to replace only the group in parenthesis in this expression :</p>

<pre><code>my_string.gsub(/&lt;--MARKER_START--&gt;(.)*&lt;--MARKER_END--&gt;/, 'replace_text')
</code></pre>

<p>so that I get : <code>&lt;--MARKER_START--&gt;replace_text&lt;--MARKER_END--&gt;</code></p>

<p>I know I could repeat the whole <code>MARKER_START</code> and <code>MARKER_END</code> blocks in the substitution expression but I thought there should be a more simple way to do this.</p>

You could do something like this:
```
```
my_string.gsub(/(<--MARKER_START-->)(.*)(<--MARKER_END-->)/, '\1replace_text\3')
```
```