What are some guidelines that could be used on CSS to ensure that it is valid at least in syntax only. The four checks that I came up with were ensuring that at least one “{“, “}”, “;” and “:” exist and if they do exist that the number of “{” and “}” matches and the number of “:” and “;” match. I also check to make sure it starts with a “.” and ends with “;}” with all possible combinations of whitespace.
Are there any other checks I could run on it just to make sure it is valid syntax?
Or better yet does anyone have a regex available that could verify this? I’m extremely new to regex but it seems like it would be able to handle all the checks I’ve mentioned.
The simplest suitable regex that I can think of is:
It doesn’t consider @charset …; directives and comments (\* … *\),
also it doesn’t check for braces in url(…) and “…” pairs in content: “…”,
but you can try adding this by yourself if you need.