fork(1) download
  1. <?php
  2. $hostnames = [
  3. 'sub1.hostname1.com',
  4. 'sub12.hostname2.com',
  5. 'suboo2.hostname3.com',
  6. 'sub2.hostname4.com'];
  7.  
  8. $filtered = array_filter($hostnames, function($hostname) {
  9. // assume that the "subdomain" is the first hostname segment, separated by "."
  10. list($subdomain, $theRest) = explode('.', $hostname, 2);
  11.  
  12. return preg_match_all('/1|2/', $subdomain) === 1;
  13. });
  14.  
  15. print_r($filtered);
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
Array
(
    [0] => sub1.hostname1.com
    [2] => suboo2.hostname3.com
    [3] => sub2.hostname4.com
)