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>Maybe other way to do this is having a <code>regex</code>, for example:</p>

<pre><code>val regExtractor = """a(b+)(c+)(d*)""".r
</code></pre>

<p>And then match the <code>String:</code></p>

<pre><code>val string = "abbbbbbbbbccdd"

val newString = string match {
  case regExtractor(g1, g2, g3) =&gt;
    s"""String Replaced: ${g1.replace(g1, "XXXXX")},
        | ${g2.replace(g2, "YYYYY")}""".stripMargin
}
</code></pre>

<p><code>newString</code> will be:</p>

<pre><code>"String Replaced: XXXXX, YYYYY"
</code></pre>

python scala grouping