3v4l.org

run code in 300+ PHP versions simultaneously
<?php $texts = ["Disposizione n. 158 del 28.1.2012", "Disposizione n.66 del 15.1.2006","Disposizione f_n_66 del 15.1.2001", "Disposizione numero 66 del 15.1.2018", "Disposizione nr. 66 del 15.1.2017", "Disposizione nr_66 del 15.1.2016", "Disposizione numero_66 del 15.1.2005"]; foreach ($texts as $text) { if (preg_match('~(?<![^\W_])n(?:r?[_.]|umero_?)\s*\K\d+~i', $text, $match)) { echo $match[0] . " found in '$text'" . PHP_EOL; } else echo "No match in $text!\n"; }

preferences:
25.96 ms | 404 KiB | 5 Q