const regex = /(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)\s*/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(.*)\\n(.*)\\n(.*)\\n(.*)\\n(.*)\\n(.*)\\s*', 'g')
const 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`;
const subst = `<h1>$1</h1><p>$2</p><br><p>$3</p><br><p>$4</p><br><p>$5</p>`;
// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);
console.log('Substitution result: ', 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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions