title: Extract only first match with Regex in Scala
body: <p>I'm trying to extract a specific string value from a JSON-formatted string in Scala.  However, this is going to be used in a production environment, so I'm concerned about efficiency.  Currently, I'm currently using the bit of code below:</p>
  
  <pre><code>val r = """identifier=\{S: ([\w\.]+),""".r
  var identifier: String = "";
  r.findAllIn(queryResult toString).matchData foreach {
    m =&gt; identifier = m.group(1)
  }
  </code></pre>
  
  <p>My concern is efficiency.  I don't need to validate the JSON itself (that's being produced by AWS, so I'm assuming it's good, and even if it's not, I can't change it), so there's no good reason to go through all the overhead of parsing it out.</p>
  
  <p>That said, can I do this more efficiently with a regex, or would I have to go down to the level of finding the first occurence of 'identifier={S: ', then the next occurence of ',' after that, and get the substring between the two?  I was trying to do something with <code>r.findFirstIn</code> but I can't figure out a way to extract the group I want from that.</p>
  
  <p>Or is there some other super efficient thing I'm not aware of that I could be doing?</p>