title: IPAddress or CIDR block matching regex
body: <p>I need to check a string for any IPv4 address or one of following CIDR blocks: /16 or /24.
  So, 192.168.0.1 should match. 192.168.0.0/16 should match. 192.168.0.0/17 should NOT match
  I'm using following regex:</p>
  
  <pre><code>re.compile(r'^([0-9]{1,3}\.){3}[0-9]{1,3}(/(16|24))?')
  </code></pre>
  
  <p>This matches all IP addresses but also strings like 192.168.0.0/aaaa</p>
  
  <p>Now, if I change the regex (remove ? at end):</p>
  
  <pre><code>re.compile(r'^([0-9]{1,3}\.){3}[0-9]{1,3}(/(16|24))')
  </code></pre>
  
  <p>It matches CIDR blocks /16 or /24 but not the IP Addresses(eg, 192.168.0.1) anymore.</p>
  
  <p>Isn't '?' supposed to check a group for optional occurrence? What am I doing wrong?</p>
  
  <p><em>Note: I know the IP address regex itself is not perfect, but I'm more interested in getting help on the issue described.</em></p>