How to exclude compression for tags (textarea, pre)?

Guys please help to add rules which will eliminate the compression tag (textarea, pre, code)

Code which is presented below, compresses all.
class MinifyMiddleware
{
 public function handle(Request $request, Closure $next)
{
 $response = $next($request);
 $buffer = $response->getContent();
 if(strpos($buffer,'<pre>') !== false)
{
 $replace = array(
 '/<!--[^\[](.*?)[^\]]-->/s' => ",
 "/<\?php/" => '<?php ',
 "/\r/" => ",
 "/>\n</" => '><',
 "/>\s+\n</" => '><',
 "/>\n\s+</" => '><',
);
}
else
{
 $replace = array(
 '/<!--[^\[](.*?)[^\]]-->/s' => ",
 "/<\?php/" => '<?php ',
 "/\n([\S])/" => '$1',
 "/\r/" => ",
 "/\n/" => ",
 "/\t/" => ",
 "/ +/" => ' ',
);
}
 $buffer = preg_replace(array_keys($replace), array_values($replace), $buffer);
$response->setContent($buffer);
 return $response;
}
}
April 4th 20 at 00:38
1 answer
April 4th 20 at 00:40
public function handle(Request $request, Closure $next)
{
 $response = $next($request);
 $buffer = $response->getContent();

 $replace = [
 '/<!--[^\[](.*?)[^\]]-->/s' => ",
 "/<\?php/" => '<?php ',
 "/\n([\S])/" => '$1',
 "/\n/" => ' ',
 // "/\r/" => ", -- Commented this parameter
 "/\t/" => ",
 "/ +/" => ' '
];

 $buffer = preg_replace(array_keys($replace), array_values($replace), $buffer);
$response->setContent($buffer);
 return $response;
 }

Find more questions by tags PHP