title: How to prevent \g subexpression from overwriting the grouped content in Ruby Regex
body: <p>eg.</p>
  <pre class="lang-rb prettyprint-override"><code>&gt; /(?&lt;ip&gt;(?:\d+\.){3}\d+)\s*(?&lt;mask&gt;\g&lt;ip&gt;)/ =~ &quot;1  abc  192.168.200.111 255.255.255.0&quot;
  &gt; $~
  =&gt; #&lt;MatchData &quot;192.168.200.111 255.255.255.0&quot; ip:&quot;255.255.255.0&quot; mask:&quot;255.255.255.0&quot;&gt;
  </code></pre>
  <p>according to the result above, <code>\g&lt;ip&gt;</code> captures &quot;255.255.255.0&quot;, but also store them to <code>ip</code> group.</p>
  <p>How to get the content of the first <code>ip</code> group: <code>192.168.200.111</code>.</p>