title: Regex for key value pair where separator characters can be embedded in the value (Scala)
body: <p>I'm trying to use a regexp to parse a string of the form:</p>
  
  <p>"a=10:30:00:b=2:c=3"</p>
  
  <p>to yield</p>
  
  <pre><code>a=10:30:00
  b=2
  c=3
  </code></pre>
  
  <p>The closest i've gotten is 
      (\w+)=(\S+?)(?=:|$), 
  but that chops off a's :30:00:</p>
  
  <pre><code>a=10
  b=2
  c=3
  </code></pre>
  
  <p>Code is in scala:</p>
  
  <pre><code>scala&gt; val s = "a=10:20:00:b=2:c=3"
  s: java.lang.String = a=10:20:00:b=2:c=3
  
  scala&gt; val R = """(\w+)=(\S+?)(?=:|$)""".r 
  R: scala.util.matching.Regex = (\w+)=(\S+?)(?=:|$)
  
  scala&gt; R findAllIn s foreach println
  a=10
  b=2
  c=3
  </code></pre>
  
  <h2>Edit</h2>
  
  <p>Modified the regex based on 
  <a href="https://stackoverflow.com/questions/14641750/regular-expression-to-match-comma-separated-list-of-key-value-where-value-can-co?rq=1">Regular expression to match comma separated list of key=value where value can contain commas</a> to handle:</p>
  
  <pre><code>val s = "foo=bar:baz:r=abc:a=10:20:00:b=2:c=3:s=xx:yy:z=100"
  
  val R = """([^=]+)=([^=]+)(?::|$)""".r
  
  R findAllMatchIn s foreach { x =&gt; println(x.subgroups) }
                                                //&gt; List(foo, bar:baz)
                                                //| List(r, abc)
                                                //| List(a, 10:20:00)
                                                //| List(b, 2)
                                                //| List(c, 3)
                                                //| List(s, xx:yy)
                                                //| List(z, 100)
  </code></pre>