const regex = /^(PANEL\s+\S+)(.*?)(?=PANEL|\Z)/gms;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(PANEL\\s+\\S+)(.*?)(?=PANEL|\\Z)', 'gms')
const str = `PANEL NORMAL
Diana and Gahriel run away with all their might. The monster is raging right behind them
Gharial (whisper)
Don’t turn back!
Diana (confused)
What--
PANEL LEFT
Gahriel signal diane to be quiet
Gharial (put his hand to his mouth signal quiet)
Shh….
PANEL FOCUS
The monster is running toward them quickly , right behind them
PANEL FULL
Diana is afraid for her own life. Her eyes wide open as the monster breathes through her.
Diana (holding her mouth with her hand)
Gasp
PANEL RIGHT
Gahriel (whisper)
Everything will be okay!
PANEL CENTER
They both stand quietly, not a single noise.,
PANEL SMALL
A sudden noise
Crack
PANEL RIGHT
The monster caught Diana and bit her head off. Gahriel in shock-terror, he can’t move.
`;
const subst = `<div class="$1">$2</div>`;
// 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