title: How can I match IPv6 addresses with a Perl regex?
body: <p>So I need to match an ipv6 address which may or may not have a mask. Unfortunately I can't just use a library to parse the string.</p>
  
  <p>The mask bit is easy enough, in this case:</p>
  
  <pre><code>(?:\/\d{1,3})?$/
  </code></pre>
  
  <p>The hard part is the different formats of an ipv6 address. It needs to match ::beef, beef::, beef::beef, etc.</p>
  
  <p>An update: I'm almost there..</p>
  
  <pre><code>/^(\:\:([a-f0-9]{1,4}\:){0,6}?[a-f0-9]{0,4}|[a-f0-9]{1,4}(\:[a-f0-9]{1,4}){0,6}?\:\:|[a-f0-9]{1,4}(\:[a-f0-9]{1,4}){1,6}?\:\:([a-f0-9]{1,4}\:){1,6}?[a-f0-9]{1,4})(\/\d{1,3})?$/i
  </code></pre>
  
  <p>I am, in this case restricted to using perl's regex.</p>