Since you tagged PHP, we can do a bit of string processing to make regex a bit simpler where we could just match a single .some_class{some_props} style and ignore all others who don't follow this property.
We can ignore all whitespaces, new lines and collect just text in a string with a space as a delimiter between each style. Now, we can explode on each one and see if it matches the style we want which has properties and collect only those and implode them later.
Snippet:
<?php
$str = '.class-1,
.class-2,
class-3 {
}
.class-4,
class-5 {
}
.class-6,
class-7 {}
.not-empty-1 {font-size: 12;}
.not-empty-2 {
font-size: 12;
}
.not-empty-3 {
font-size: 12;margin-top:25px;
}';
$new_str = '';
for($i=0;$i<strlen($str);++$i){
if(strlen(trim($str[$i])) === 0) continue; // skip new lines,spaces, line feeds etc
$new_str .= $str[$i];
if($str[$i] == '}') $new_str .= ' ';
}
$results = [];
foreach(explode(" ",$new_str) as $css_style){
if(preg_match('/^(.+?)\{(.+?)\}$/',$css_style,$matches)){
$results[] = implode("\n",[$matches[1],"{\n ".$matches[2]."\n}"]);
}
}
echo implode("\n\n",$results);
Demo: https://3v4l.org/67mXE
[^{}\r\n]+(?:\r?\n[^{}\r\n]+)*{\s*}regex101.com/r/QTzEu7/1^(?:[^{}\r\n]*\R)*+[^{]+{\s*}\s*will be more efficient than what I posted earlier. Please post an answer as you were first to solve this. Making a pattern more efficient is a different issue :)