Try the following:
$str=<<<STR STR; $match=null; preg_match_all("/\*[[:space:]]*(@todo[^(\*\/$)]*)/i",$str,$match,PREG_SET_ORDER); print_r($match);
echoes
Array ( [0] => Array ( [0] => * @todo name another-name taskID 1 [1] => @todo name another-name taskID 1 ) [1] => Array ( [0] => * @todo name another-name taskID 2 [1] => @todo name another-name taskID 2 ) )
Not a perfect solution (note the end of the line in $match[0][0] ).
source share