$re = '/^(?!\t)(?:(FULL|SMALL)\W*)?([^\n]+)(.+?)(?=^(?!\t)\w+?|$(?!\n))/ms';
$str = '
Gahriel and Diana are standing in the living room.
FULL: The living room has SOFA and a table. On the table have CUPCAKE and a NOTE at the bottom (or somewhere that doesn’t present the first time we see it.) Gahriel is walking to the kitchen calling out his mom.
Gahriel
Make yourself at home!
Diana
okay!
Gahriel
(calling out his mom)
Mom?
Where is she?
SMALL- Diana inside the living room with Gabriel. She’s amazed with the picture on the wall related to his mother and young Gahriel.
Diana ask
Is this you and your mom?
Gahriel (smiling)
Haha, yup.
That’s me.
Diana (yelling and laughing so loud and keep talking)
Diana
Argh.. that’s so cute.
Look at how chubby you are!
';
$subst = "<div class=\"PANEL $1\">\n<div class=\"action\">$2</div></div>\n\n";
$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