title: Regex optional groups and digit length
body: <p>Maybe some regex-Master can solve my problem.</p>
  <p>I have a big list with many addresses with no seperators( , ; ).
  The address string contains following Information:</p>
  <ul>
  <li>The first group is the <strong>street name</strong></li>
  <li>The second group is the <strong>street number</strong></li>
  <li>The third group is the <strong>zipcode</strong> (optional)</li>
  <li>The last group is the <strong>town name</strong> (optional)</li>
  </ul>
  <p><a href="https://i.stack.imgur.com/OZVQu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OZVQu.png" alt="regex_png" /></a></p>
  <p>As you can see on the image above the last two test strings are not matching.
  I need the last two regex groups to be optional and the third group should be either 4 or 5 digits.</p>
  <p>I tried <code>(\d{4,5})</code> for allowing 4 and 5 digits. But this only works halfways as you can see here: <a href="https://regex101.com/r/ZurqHh/1" rel="nofollow noreferrer">https://regex101.com/r/ZurqHh/1</a><br />
  <a href="https://i.stack.imgur.com/gK8n3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gK8n3.png" alt="regex_4_5_digits" /></a>
  (This sometimes mixes the street number and zipcode together)</p>
  <p>I also tried <code>(?:\d{5})?</code> to make the third and fourth group optional. But this destroys my whole group layout...
  <a href="https://regex101.com/r/EgxeMy/1" rel="nofollow noreferrer">https://regex101.com/r/EgxeMy/1</a></p>
  <p><a href="https://i.stack.imgur.com/EbzAr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EbzAr.png" alt="regex_optional" /></a></p>
  <p>This is my current regex:</p>
  <pre><code>/^([a-zäöüÄÖÜß\s\d.,-]+?)\s*([\d\s]+(?:\s?[-|+\/]\s?\d+)?\s*[a-z]?)?\s*(\d{5})\s*(.+)?$/im
  </code></pre>
  <p>Try it out yourself:
  <a href="https://regex101.com/r/zC8NCP/1" rel="nofollow noreferrer">https://regex101.com/r/zC8NCP/1</a></p>
  <p>My brain is only farting at this moment and i can't think straight anymore.</p>
  <p>Please help me fix this problem so i can die in peace.</p>