Let's say I have a css file as shown...
span {
//whatever
}
.block {
//whatever
}
.block, .something {
//whatever
}
.more,
h1,
h2 {
//whatever
}
I want to extract all class names and put it into an array, but I want to keep the structure, so the array will look like...
["span", ".block", ".block, .something", ".more, h1, h2"]
So there are four items.
This is my attempt...
$homepage = file_get_contents("style.css");
//remove everything between brackets (this works)
$pattern_one = '/(?<=\{)(.*?)(?=\})/s';
//this regex does not work properly
$pattern_two = "/\.([\w]*)\s*{/";
$stripped = preg_replace($pattern_one, '', $homepage);
$selectors = array();
$matches = preg_match_all($pattern_two, $stripped, $selectors);
what is the proper regex to use for pattern 2?