fork download
  1. <?php
  2.  
  3. $re = '/[0-9]+\.[0-9]+/';
  4. $str = 'I am trying to use regex to extract a certain syntax, in my case something like "10.100" or "20.111", in which 2 numbers are separated by dot(.) . So if I provide "a 10.100", it will extract 10.100 from the string. If I provide "a 10.100 20.101", it will extract 10.100 and 20.101.';
  5. preg_match_all($re, $str, $matches);
  6. print_r($matches[0]);
Success #stdin #stdout 0.01s 82944KB
stdin
Standard input is empty
stdout
Array
(
    [0] => 10.100
    [1] => 20.111
    [2] => 10.100
    [3] => 10.100
    [4] => 10.100
    [5] => 20.101
    [6] => 10.100
    [7] => 20.101
)