I assume that you’re using php, based on that, try this:
<?
$text = "#id .class .anotherclass { color: #555 } #anotherid .class { color : #fff; }";
function removespaces($matches)
{
return $matches[1].str_replace(" ", "", $matches[2]);
}
echo preg_replace_callback( "/(#.*?)(\{.*?\})/i", "removespaces", $text);
?>
DEMO:
solved Regex to remove white spaces [closed]