3v4l.org

run code in 300+ PHP versions simultaneously
<?php $pattern='/^(\p{Pd}+\s*2\.2\.|2\.2\.)/mu'; $texts = array( "– 2.2.04 R", "–– 2.2.04.10 C", "–– 2.2.04.1 CO", "–– 2.2.04.2 CO", "–– 2.2.04.3 CO", "–– 2.2.04.4 CO", "–– 2.2.04.5 CO", "–– 2.2.04.6 CO", "–– 2.2.04.7 CO", "–– 2.2.04.8 CO", "–– 2.2.04.9 CO", "foooooooooooo", "barrrrrrrrrr", "-- foobar", "- 1123", ); foreach($texts as $key=>$text) { if(preg_match($pattern, $text)) { $final_texts[] = $text; } } print_r($final_texts);

preferences:
39.85 ms | 402 KiB | 5 Q