$re = '/^(PANEL\s+\S+)(.*?)(?=PANEL|\Z)/ms';
$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.
';
$subst = "<div class=\"$1\">$2</div>";
$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