Scala substring match to match noun : <p>Is there any regex to match substring if they have space in between in scala ?</p>

<p>For eg:</p>

<pre><code> "hero 6 go pro" contains "gopro" should return true
 "go pro hero 6 " contains "gopro" should return true
</code></pre>

<p>I tried :</p>

<pre><code>   def matchWords(input: Seq[Char], words: Seq[Char]): Boolean = (input, words) match {
         case (Seq(), Seq() | Seq(' ', _*)) =&gt; true
         case (Seq(), _) =&gt; false
         case (Seq(a, tail@_*), Seq(b, rest@_*)) if a == b =&gt; matchWords(tail, rest)
         case (_, Seq(' ', rest@_*)) =&gt; matchWords(input, rest)
         case _ =&gt; false
       }
</code></pre>

<p>but </p>

<p>matchWords("gopro", "hero 6 go pro") returns false</p>

<p>though this matchWords("fitbit", "fit bit versa") return true. </p>

<p>The string should match nouns. </p>

<p>Any idea what I am doing wrong here ?</p>

<p>Thanks,
Shalini </p>
