$re = '/^.*\\\\r\\\\n\|\*(Task 1)\*\|(.*)\|(.*)\|(.*)\|(.*)\|\\\\r\\\\n\|\*(Task 2)\*\|(.*)\|(.*)\|(.*)\|(.*)\|\\\\r\\\\n\|\*(Task 3)\*\|(.*)\|(.*)\|(.*)\|(.*)\|\\\\r\\\\n\|\*(Task 4)\*\|(.*)\|(.*)\|(.*)\|(.*)\|$/m';
$str = '|| ||Du Date||Done on||OK/NOK||Remarks||\\r\\n|*Task 1*| | | | |\\r\\n|*Task 2*| | | | |\\r\\n|*Task 3*| | | | |\\r\\n|*Task 4*| 15/03/23| | | See document X|';
$subst = "{\"ACTION\":[{\"TITLE\":\"$1\",\"DUE DATE\":\"$2\",\"DONE ON\":\"$3\",\"NOTE\":\"$5\"},{\"TITLE\":\"$6\",\"DUE DATE\":\"$7\",\"DONE ON\":\"$8\",\"NOTE\":\"$10\"},{\"TITLE\":\"$11\",\"DUE DATE\":\"$12\",\"DONE ON\":\"$13\",\"NOTE\":\"$15\"},{\"TITLE\":\"$16\",\"DUE DATE\":\"$17\",\"DONE ON\":\"$8\",\"NOTE\":\"$20\"}]}";
$result = preg_replace($re, $subst, $str);
echo "The result of the substitution is ".$result;
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php