How can I get subgroups of the match in Scala?
<p>I have the following in python:</p>

<pre><code>  regex.sub(lambda t: t.group(1).replace(" ", "  ") + t.group(2),string)    
</code></pre>

<p>where <code>regex</code> is a Regular Expression and <code>string</code> is a filled String. </p>

<p>So I am trying to do the same in Scala, using <code>regex.replaceAllIn(...)</code> function instead of python<code>sub</code>. However, I don't know how to get the subgroups that match.</p>

<p>Is there something similar to python function <code>group</code> in Scala?</p>

<p>You can use <code>replaceAll</code>, and use <code>$n</code>, where "n" is the group you want to match. For example:</p>

<pre><code>yourString.replaceAll(yourRegex, "$1")
</code></pre>

<p>Replaces the matched parts with the first group.</p>

python scala grouping