3v4l.org

run code in 300+ PHP versions simultaneously
<?php $re = '~[-+]?[0-9]*\.?[0-9]+(?:[eE][-+]?[0-9]+)?|\d+|(?>\p{L}\p{M}*+)+~u'; $text = "The example number 2 is a bad example it will not \ncount numbers and punctuations !! X is 2.5674."; if (preg_match_all($re, $text, $matches)) { echo count($matches[0]) . PHP_EOL; print_r($matches[0]); }
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
18 Array ( [0] => The [1] => example [2] => number [3] => 2 [4] => is [5] => a [6] => bad [7] => example [8] => it [9] => will [10] => not [11] => count [12] => numbers [13] => and [14] => punctuations [15] => X [16] => is [17] => 2.5674 )

preferences:
167.78 ms | 408 KiB | 5 Q