3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $sites = array( 'site.ru', 'www.site.ru', 'en.site.ru', 'www.en.site.ru', 'de.site.ru', 'www.de.site.ru', ); foreach($sites as $site) { preg_match_all('/^(?:www\.)?(en|de)?(.*)/i', $site, $matches); var_dump($matches); }
based on LHflA
Output for 5.6.0 - 7.3.0alpha1
array(3) { [0]=> array(1) { [0]=> string(7) "site.ru" } [1]=> array(1) { [0]=> string(0) "" } [2]=> array(1) { [0]=> string(7) "site.ru" } } array(3) { [0]=> array(1) { [0]=> string(11) "www.site.ru" } [1]=> array(1) { [0]=> string(0) "" } [2]=> array(1) { [0]=> string(7) "site.ru" } } array(3) { [0]=> array(1) { [0]=> string(10) "en.site.ru" } [1]=> array(1) { [0]=> string(2) "en" } [2]=> array(1) { [0]=> string(8) ".site.ru" } } array(3) { [0]=> array(1) { [0]=> string(14) "www.en.site.ru" } [1]=> array(1) { [0]=> string(2) "en" } [2]=> array(1) { [0]=> string(8) ".site.ru" } } array(3) { [0]=> array(1) { [0]=> string(10) "de.site.ru" } [1]=> array(1) { [0]=> string(2) "de" } [2]=> array(1) { [0]=> string(8) ".site.ru" } } array(3) { [0]=> array(1) { [0]=> string(14) "www.de.site.ru" } [1]=> array(1) { [0]=> string(2) "de" } [2]=> array(1) { [0]=> string(8) ".site.ru" } }