title: Why are no matches found when ever regex char optional
body: <p>I'm very puzzled about why this is happening, and hoping someone can explain the mechanics of what is happening in the regex engine.</p>
  
  <p>Whilst working on codewars exercise "Did you mean...?" in Javascript, I was trying to calculate how many of the characters in word1 appear in word2. I'm attempting to match with each char as its own match group, so that later on I can count the number of successful matches in the array, and use that to find out how similar the two words are.</p>
  
  <p>Please don't give me tips on how to solve the codewars challenge, just help me understand what is going on here.</p>
  
  <p>I tried:</p>
  
  <pre><code>'berry'.match(/(c?)(h?)(e?)(r?)(r?)(y?)/)
  </code></pre>
  
  <p>and got no matches</p>
  
  <pre><code>&gt; ["", "", "", "", "", "", ""]
  </code></pre>
  
  <p>This is a mystery to me. Having searched Regular-expressions.info, the <code>?</code> (make preceding character optional) is greedy, so although no matches is valid for the regex, shouldn't it be trumped by the greedy version first? I was expecting this:</p>
  
  <pre><code>&gt; ["", "", "", "e", "r", "r", "y"]
  </code></pre>
  
  <p>Other things I have tried:
  - cherry match cherry works as I expected</p>
  
  <pre><code>'cherry'.match(/(c?)(h?)(e?)(r?)(r?)(y?)/)
  &gt; ["cherry", "c", "h", "e", "r", "r", "y"]
  </code></pre>
  
  <p>cherl match cherry works as I would expect too</p>
  
  <pre><code>'cherl'.match(/(c?)(h?)(e?)(r?)(r?)(y?)/)
  &gt; ["cher", "c", "h", "e", "r", "", ""]
  </code></pre>
  
  <p>And if I remove the <code>?</code> from the final <code>y</code>, it also works as expected:</p>
  
  <pre><code>'berry'.match(/(c?)(h?)(e?)(r?)(r?)(y)/)
  &gt; ["erry", "", "", "e", "r", "r", "y"]
  </code></pre>
  
  <p>So why does adding a <code>?</code> onto the final <code>y</code> mean I no longer see any matched characters?</p>
  
  <p>Although I have tried this in JS, I get the same in PY and PCRE</p>