I am trying to write a regex that matches a valid CSS class name structure. I have this so far:
$pattern = "([A-Za-z]*\.[A-Za-z]+\s*{)";
$regex = preg_match_all($pattern, $html, $matches);
However, a class name can be in the following formats that my regex won't match:
p.my_class{
}
p.thisclas45{
}
These are just some cases, I've looked around to find the rules of how you can name a class in a style block but couldn't find anything. Anyone know where the rules for the class naming conventions are?
Are there any more cases that I need to consider? What regex would you use to match a class name?
I have already narrowed it down to a style block using the PHP DOM Document class.
#. @ Álvaro - it does match it as I have a*which is 0 or more characters infront of the..(and)(as well as{},[]and<>) may be used as delimiters, i.e.,"([A-Za-z]*\.[A-Za-z]+\s*{)"is fully valid pattern. If another delimiter is used, there's no need to put whole pattern in(), i.e., it can be either(something)or#something#, and there's no need to write#(something)#, as you would use whole pattern as subpattern in such case.