fork download
  1. <?php
  2.  
  3. $string = "Lot99. Is it 1+3 or 5 or 6.53";
  4. $regex = '~
  5. (?:\d+\.\d+) # looks for digits with a point (float)
  6. (*SKIP)(*FAIL) # all of the left alternatives should fail
  7. | # OR
  8. ([.\s+]+) # a point, whitespace or plus sign
  9. # this should match and be captured
  10. # for PREG_SPLIT_DELIM_CAPTURE
  11. ~x'; # verbose modifier
  12. $parts = preg_split($regex, $string, 0, PREG_SPLIT_DELIM_CAPTURE);
  13. print_r($parts);
  14. ?>
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Lot99
    [1] => . 
    [2] => Is
    [3] =>  
    [4] => it
    [5] =>  
    [6] => 1
    [7] => +
    [8] => 3
    [9] =>  
    [10] => or
    [11] =>  
    [12] => 5
    [13] =>  
    [14] => or
    [15] =>  
    [16] => 6.53
)