3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $items = array( '<title>Something (TV 1999-2000)</title>' ,'<title>Something (1999-2000)</title>' ,'<title>Something (19999-2000)</title>' ,'<title>Something (99000)</title>' ,'<title>Something (2000)</title>' ); $regex = "/<title>.*?\(.*?(\d{4}(-\d{4})?).*?\)<\/title>/is"; foreach($items AS $k => $str) { preg_match($regex, $str, $matches[$k]); } print_r($matches); ?>
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Array ( [0] => Array ( [0] => <title>Something (TV 1999-2000)</title> [1] => 1999-2000 [2] => -2000 ) [1] => Array ( [0] => <title>Something (1999-2000)</title> [1] => 1999-2000 [2] => -2000 ) [2] => Array ( [0] => <title>Something (19999-2000)</title> [1] => 1999 ) [3] => Array ( [0] => <title>Something (99000)</title> [1] => 9900 ) [4] => Array ( [0] => <title>Something (2000)</title> [1] => 2000 ) )