Can't match string literal in regular expression
<p>I'm trying to match string literals with the possibility of internal escaped strings</p>

<p>What I've arrived at so far looks a little something like this:</p>

<pre><code>def matchStringLiteral(input: String) = {
  val strLit = """(\"(\\.|[^"])*\")""".r
  input match {
    case strLit(s) =&gt; s"matched literal $s"
    case _ =&gt; "didn't match anything"
  }
}
</code></pre>

<p>Except when I try to use it like so:</p>

<pre><code>val str = "\"welcome to \\\"GenericWebsiteName.com\\\"\""
println(matchStringLiteral(str))
</code></pre>

<p>it prints <code>"didn't match anything"</code> despite working fine on <a href="https://regex101.com/r/rL0yP6/1" rel="nofollow">Regex101</a></p>

<p>Can someone explain to me what I'm doing wrong, and more importantly <em>why</em>?</p>