title: Gatling, Scala, regex and shortest match
body: <p>I have a problem I cannot solve. I'm willing to capture a pattern with a regex depending on a variable and I want to get the shortest match (not the first occurence that matches but the last which is also the shortest)</p>
  
  <p>Here is the gatling pseudo code</p>
  
  <pre><code>val rubriquesPath=Seq("toto","tata","titi","tutu")
  
  .foreach(rubriquesPath,"rubrique"){
      exec(http("${rubrique}")
          .get("/" + "${rubrique}")
          .check(regex("""URLPage":"(.+?)".*?"path":"/${rubrique}/""").saveAs("tms")))
      .exec(http("TMS " + "${rubrique}")
          .get("${tms}"))
  }
  </code></pre>
  
  <p>Data sample (which is in fact a single line)</p>
  
  <pre><code>{"displayName":"Bienvenue","URLPage":"preprod.test.com/page/ac73b/4579.json?cache=60000","BOName":"Test","path":"/toto/"},
  {"displayName":"Bienvenue","URLPage":"preprod.test.com/page/ac73b/4774.json?cache=60000","BOName":"Test","path":"/tata/"},
  {"displayName":"Bienvenue","URLPage":"preprod.test.com/page/ac73b/4745.json?cache=60000","BOName":"Test","path":"/titi/"},
  {"displayName":"Bienvenue","URLPage":"preprod.test.com/page/ac73b/4799.json?cache=60000","BOName":"Test","path":"/tutu/"} 
  </code></pre>
  
  <p>In this example, I would like to capture the URLPage value depending on a variable in a sequence
  I.E</p>
  
  <ul>
  <li>for toto: preprod.test.com/page/ac73b/4579.json?cache=60000</li>
  <li>for tata: preprod.test.com/page/ac73b/4774.json?cache=60000</li>
  </ul>
  
  <blockquote>
    <p>regex("""URLPage":"(.+?)".*?"path":"/${rubrique}/"""</p>
  </blockquote>
  
  <p>matches and captures the string in italic below which is logical but that's not what I'm trying to do (get the pattern in bold)</p>
  
  <p>For tata</p>
  
  <blockquote>
    <p>"URLPage":"<em>preprod.test.com/page/ac73b/4579.json?cache=60000</em>","BOName":"Test","path":"/toto/"},
            {"displayName":"Bienvenue","URLPage":"<strong>preprod.test.com/page/ac73b/4774.json?cache=60000</strong>","BOName":"Test","path":"/tata/</p>
  </blockquote>
  
  <p>For tutu</p>
  
  <blockquote>
    <p>"URLPage":"<em>preprod.test.com/page/ac73b/4579.json?cache=60000</em>","BOName":"Test","path":"/toto/"},
        {"displayName":"Bienvenue","URLPage":"preprod.test.com/page/ac73b/4774.json?cache=60000","BOName":"Test","path":"/tata/"},
        {"displayName":"Bienvenue","URLPage":"preprod/test.com/page/ac73b/4745.json?cache=60000","BOName":"Test","path":"/titi/"},
        {"displayName":"Bienvenue","URLPage":"<strong>preprod/test.com/page/ac73b/4799.json?cache=60000</strong>","BOName":"Test","path":"/tutu/"} </p>
  </blockquote>
  
  <p>How can I properly do this?</p>
  
  <p>Thanks</p>
  
  <p>Jérôme</p>