title: Ruby non-greedy modifier did not apply?
body: <p>I have a regexp with a non-greedy modifier which does not seem to work. I have tried so many variations of the regexp and various other ways I could think of, without success, that I am losing my head</p>
  
  <p>I want to remove all the empty strings embedded in the string <code>s</code> below. With my regexp I was expecting to remove all the things that matched something=""</p>
  
  <pre><code>s = 'a,b="cde",f="",g="hi",j=""'
  
  puts s; puts s.gsub( /,.+?="",?/ , "," ).chomp(','); nil
  </code></pre>
  
  <p>Expected:</p>
  
  <pre><code>a,b="cde",g="hi"
  </code></pre>
  
  <p>What I get:</p>
  
  <pre><code>a,g="hi"
  </code></pre>
  
  <p>Why isn't the <code>.+?</code> non greedy in the <code>gsub</code> regexp below?</p>
  
  <p>It works if I constrain the <code>.</code> to a set of characters <code>[\w\d_-]</code>, but that forces me to do assumptions:</p>
  
  <pre><code>puts s; puts s.gsub( /,[\w\d_-]+?=""/ , "" ).chomp(','); nil
  
  # outputs:
  a,b="cde",f="",g="hi",j=""
  a,g="hi"
  </code></pre>
  
  <p>It also works if I do some sort of negative lookup like:</p>
  
  <pre><code>puts s; puts s.gsub( /,.+?="",?/ , "," ).chomp(','); nil
  
  # outputs:
  a,b="cde",f="",g="hi",j=""
  a,g="hi"
  </code></pre>
  
  <p>But still I do not understand why it did not work in the first case.</p>