title: Ruby Regular Expression for matching any subdomains and the top level domain
body: <p>I'm trying to create a regex that will optionally match any subdomains, and match the TLD. For example, it should match…</p>
  
  <ul>
  <li><a href="https://example.com" rel="nofollow noreferrer">https://example.com</a></li>
  <li><a href="http://example.com" rel="nofollow noreferrer">http://example.com</a></li>
  <li><a href="https://test.example.com" rel="nofollow noreferrer">https://test.example.com</a></li>
  <li>test.example.com</li>
  <li>example.com</li>
  </ul>
  
  <p>It should not match…</p>
  
  <ul>
  <li>fakeexample.com</li>
  <li><a href="https://fakeexample.com" rel="nofollow noreferrer">https://fakeexample.com</a></li>
  <li>fake.fakeexample.com</li>
  </ul>
  
  <p>I have this so far, which matches subdomains, but does not match when at the top level domain.
  <code>(\A|(https?:\/\/))?(\w*|\S*)\.{1}example\.com</code></p>