title: Regex syntax for a string containing only [a-zA-Z0-9.-_] with max length of 20 and cannot end with a '.' and can only contain at most two '.'
body: <h2>Issue</h2>
  
  <p>I cannot get the regex syntax down for the following conditions:</p>
  
  <ul>
  <li>Length 1-20</li>
  <li>Can only contain the following chars <code>a-zA-Z0-9.-_</code></li>
  <li>Cannot end with a <code>.</code></li>
  <li>Can only have 0, 1, or 2 occurrences of a <code>.</code></li>
  </ul>
  
  <hr>
  
  <h2>Input</h2> 
  
  <h3>Pass</h3>
  
  <p>The following items should pass the regex validation</p>
  
  <pre><code>dummy.txt
  dummy.tar.gz
  .dummy
  </code></pre>
  
  <h3>Fail</h3>
  
  <p>The following items should fail the regex validation</p>
  
  <pre><code>dummy.
  dummy.dummy.tar.gz
  dummydummydummy.tar.gz
  </code></pre>
  
  <ol>
  <li>Ends with <code>.</code></li>
  <li>More than 2 <code>.</code></li>
  <li>More than 20 characters</li>
  </ol>
  
  <hr>
  
  <h2>Attempts</h2>
  
  <p>Here's the syntax I have so far, which works, but I can't figure out how to add the "no more than two <code>.</code>" constraint:</p>
  
  <pre><code>^[a-zA-Z0-9.-_]{1,20}(?&lt;!\.)$
  </code></pre>
  
  <p>Thanks.</p>