PHP Regex匹配特定的css类名+:before伪

Been more than 6 hours trying to find best PHP regex to match a specific class name + :before pseudo. For example I have css code like this

h1 {
  font-size: 3em;
  line-height: 1.65em;
}

p{line-height: 1.5em; margin: 10px 0;}

.action-admin:before{
   content: "";
   display: block;
   width: 50px;
   height: 50px;
}

.action-user:before{
   content: "";
   display: block;
   width: 20px;
   height: 20px;
}

footer{
   clear: both;
}

so, I want to search all css code that have class name match with '.action-{anyotherwords}:before' and listed them in a php variable (will process this to next action)

so, in simple words - I only want to get these code below from my css above

.action-admin:before{
   content: "";
   display: block;
   width: 50px;
   height: 50px;
}

.action-user:before{
   content: "";
   display: block;
   width: 20px;
   height: 20px;
}

You can use this regex to find all these blocks:

\.action-[\w-]+:before\s*?\{[^}]+\}

enter image description here

Example:

preg_match_all("/\.action-[\w-]+:before\s*?\{[^}]+\}/", $css, $matches);
$actionCSS = implode("

", $matches[0]);

The CSS code with only the action blocks will then be in $actionCSS.