title: PHP RegEx: a Pattern to Validate the Second Level Domain
body: <p><strong>Note:</strong> this is a theoretical question about PHP flavor of regex, not a practical question about validation in PHP. I am merely using Domain Names for lack of a better example.</p>
  
  <p>"Second Level Domain" refers to the combination of letters, numbers, period signs, and/or dashes that are placed between http:// or <code>http://www.</code> and .com (.co, .info, .etc) .</p>
  
  <p>I am only interested in second level domains that use English version of Latin alphabet. </p>
  
  <p>This pattern:</p>
  
  <pre><code>[A-Za-z0-9.-]+
  </code></pre>
  
  <p>matches valid domain names, such as stackoverflow, StackOverflow, stackoverflow.co (as in stackoverflow.co.uk), stack-overflow, or stackoverflow123. </p>
  
  <p>However, the same pattern would also match something like stack...overflow, stack---over--flow, ........ , -------- , or even . and -. </p>
  
  <p>How can that pattern be rewritten, to indicate that period signs and dashes, even though they can be used multiple times in a node, </p>
  
  <ul>
  <li>cannot be used without other symbols, </li>
  <li>cannot be placed twice or more side by side with each other, </li>
  <li>and cannot be placed in the beginning or end of the node? </li>
  </ul>
  
  <p>Thank you in advance!  </p>