fork(6) download
  1. <?php
  2.  
  3. $str = "Lorem ipsum [1. dolor sit amet, [consectetuer adipiscing] elit.]. Aenean commodo ligula eget dolor.[2. Dolor, [consectetuer adipiscing] elit.] Aenean massa[3. Lorem ipsum] dolor.";
  4. preg_match_all('/\[(?>[^\[\]]|(?R))*]/', $str, $matches);
  5. $res = array_map(function($el) {
  6. return preg_replace('/^\[\d+\.(.*?)\s*\]$/s', '$1', $el);
  7. },
  8. $matches[0]);
  9. print_r($res);
  10.  
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
Array
(
    [0] =>  dolor sit amet, [consectetuer adipiscing] elit.
    [1] =>  Dolor, [consectetuer adipiscing] elit.
    [2] =>  Lorem ipsum
)