title: Rough regex for multiline text with optional group and named captures at the end of each match
body: <p>I want to capture some ifconfig output (example below) and from that, I want to have interface names, flags, IP address and netmask (if they exist), status (which also may not exist in loopback devices)</p>
  
  <pre><code>re0: flags=8843&lt;UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST&gt; metric 0 mtu 1500
      options=8209b&lt;RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,WOL_MAGIC,LINKSTATE&gt;
      ether 00:30:18:c6:03:f0
      inet 192.168.16.67 netmask 0xffffff00 broadcast 192.168.16.255 
      inet6 fe80::230:18ff:fec6:3f0%re0 prefixlen 64 scopeid 0x1 
      nd6 options=23&lt;PERFORMNUD,ACCEPT_RTADV,AUTO_LINKLOCAL&gt;
      media: Ethernet autoselect (1000baseT &lt;full-duplex&gt;)
      status: active
  re1: flags=8843&lt;UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST&gt; metric 0 mtu 1500
      options=8209b&lt;RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,WOL_MAGIC,LINKSTATE&gt;
      ether 00:30:18:c6:03:f1
      inet6 fe80::230:18ff:fec6:3f1%re1 prefixlen 64 scopeid 0x2 
      nd6 options=23&lt;PERFORMNUD,ACCEPT_RTADV,AUTO_LINKLOCAL&gt;
      media: Ethernet autoselect (none)
      status: no carrier
  lo0: flags=8049&lt;UP,LOOPBACK,RUNNING,MULTICAST&gt; metric 0 mtu 16384
      options=600003&lt;RXCSUM,TXCSUM,RXCSUM_IPV6,TXCSUM_IPV6&gt;
      inet6 ::1 prefixlen 128 
      inet6 fe80::1%lo0 prefixlen 64 scopeid 0x3 
      inet 127.0.0.1 netmask 0xff000000 
      nd6 options=21&lt;PERFORMNUD,AUTO_LINKLOCAL&gt;
  </code></pre>
  
  <p>and I have managed take it up to this point;</p>
  
  <pre><code>^(?&lt;interface&gt;(?:[^\s:]+))(?=: flags):\s(?:flags=\d+&lt;(?&lt;flags&gt;(?:[\w,]+))&gt;).*?(?:(?:inet (?&lt;ip_address&gt;(?:\d+\.?){4})|$)? (?:netmask 0x(?&lt;netmask&gt;(?:\w++\.?))|$)).*?(?:status: (?&lt;status&gt;(?:[\w ]++)))
  </code></pre>
  
  <p>but this only captures normal interfaces not loopback device because of status line. And if you make the status line optional by putting a question mark at end of status line match group, it does not match even if status line exist for some reasons that I can not manage to understand. </p>
  
  <p>A problem waiting for geniuses all over the world to solve it :)</p>