title: Capturing optional groups in regex
body: <p>I need to capture the optional texts in a pattern, with the extracted examples <code>i</code>, <code>9</code>, <code>Caffè</code> and <code>you</code> in the following matched scenarios:</p>
  
  <ul>
  <li><p>Valid matches:</p>
  
  <pre><code>love!
  9 love!
  love Caffè!
  i love you!
  </code></pre></li>
  <li><p>Invalid matches:</p>
  
  <pre><code>love
  iloveyou
  </code></pre></li>
  </ul>
  
  <p>My <a href="https://stackoverflow.com/questions/42464120/parsing-regex-with-alternatives-and-optionals">rule</a>: <code>[*] love [*]!</code>, with <code>[*]</code> meaning blank text can be accepted to be captured.</p>
  
  <p>I tried to make the regex <code>((?:.+) )?love( (?:.+))?!</code> (<a href="https://regex101.com/r/aJWQHI/2" rel="nofollow noreferrer">online</a>) but it failed to capture the correct texts.</p>