3v4l.org

run code in 500+ PHP versions simultaneously
<?php $re = '/^([^\d\r\n]*)\h*(\d+(?:\h+\d+)*)\h*([^\d\r\n]*)$/m'; $str = 'from 8 000 packs test from 8 000 packs test 432534534 from 344454 packs 45054 packs 04 555 434654 54 564 packs'; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); foreach($matches as $match) { list(,$before, $num, $after) = $match; echo sprintf( "before: %s\nnum:%s\nafter:%s\n--------------------\n", $before, preg_replace("/\h+/", "", $num), $after ); }
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.21, 8.5.0 - 8.5.6
before: from num:8000 after:packs -------------------- before: test from num:8000 after:packs test -------------------- before: num:432534534 after: -------------------- before: from num:344454 after:packs -------------------- before: num:45054 after:packs -------------------- before: num:04555 after: -------------------- before: num:434654 after: -------------------- before: num:54564 after:packs --------------------

preferences:
106.26 ms | 1333 KiB | 4 Q