title: Rails - Filter by domain of the URL PostgreSQL
body: <p>I have one table pages which has <code>url</code> field. I want to filter those records by domain name.
  Below are the sample domains from list of URL. </p>
  
  <ul>
  <li><a href="http://test.host" rel="nofollow noreferrer">http://test.host</a> </li>
  <li><a href="http://localhost:3000" rel="nofollow noreferrer">http://localhost:3000</a></li>
  <li><a href="https://www.testing.staging.io" rel="nofollow noreferrer">https://www.testing.staging.io</a></li>
  <li><a href="https://staging.example.com" rel="nofollow noreferrer">https://staging.example.com</a></li>
  </ul>
  
  <p>I checked <a href="https://stackoverflow.com/questions/47528966/regex-for-postgresql-for-getting-domain-with-sub-domain-from-url-website">this</a> answer. But REGEXP_REPLACE is not working in where condition.</p>
  
  <p>Below is the query that I tried but it is only allowing to filter by hostname, I want regex which work for the domain name. </p>
  
  <pre><code>Page.where("substring(url from '.*://([^/]*)') in (?)", ['test.host'])
  </code></pre>
  
  <p>The request parameter for domains will be ['<a href="http://test.host" rel="nofollow noreferrer">http://test.host</a>'] not ['test.host'].</p>
  
  <p>I am looking for the best solution to tackle this problem. Thank you in advance.</p>