$re = '/(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)\s*/';
$str = '1 Question
2 Answer 1
3 Answer 2
4 Answer 3
5 Answer 4
6 Answer 5
7 Question
8 Answer 1
9 Answer 2
10 Answer 3
11 Answer 4
12 Answer 5';
$subst = "<h1>$1</h1><p>$2</p><br><p>$3</p><br><p>$4</p><br><p>$5</p>";
$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