title: regular expression for many ips separated by comma
body: <p>i'm intended to build a regular expression that will match with a block of ips separated by comma.
  well as far as i have is a regullar expression for ips and a comma followed by a breakline character, but i need to set this condition:</p>
  
  <p>if threre is the last line (no breakline char) comma is optional
  if there is evrything else, must be a comma followed by breakline.</p>
  
  <p>would you help me to complete the regex please ?</p>
  
  <p>this is the regex that i'm building</p>
  
  <pre><code>((25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)(,\n)?)*
  </code></pre>
  
  <p>this is the testing block</p>
  
  <pre><code>192.168.1.1,
  192.56.3.23,
  189.35.2.2,
  198.23.45.56
  192.168.3.24
  </code></pre>
  
  <p>the 198.23.45.56 shouldn't be valid since is not the last line and there is not a comma at the end of the line.</p>
  
  <p>I'm using this validator online <a href="http://regexpal.com/" rel="nofollow">http://regexpal.com/</a> to test the regex.</p>
  
  <p>Regards.</p>