fork download
  1. <?php
  2.  
  3. $str = "x 1 2 3 4 5";
  4. $re1 = '~(?:x|(?!^)\G)\s*\K\d+~';
  5. preg_match_all($re1, $str, $matches);
  6. var_dump($matches);
  7.  
  8. $re2 = '~\d+(?:\s+\d+)*~';
  9. if (preg_match($re2, $str, $match2)) {
  10. print_r(preg_split("/\\s+/", $match2[0]));
  11. }
  12.  
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
array(1) {
  [0]=>
  array(5) {
    [0]=>
    string(1) "1"
    [1]=>
    string(1) "2"
    [2]=>
    string(1) "3"
    [3]=>
    string(1) "4"
    [4]=>
    string(1) "5"
  }
}
Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
)