开发者

Verify CSS is valid syntax [closed]

Closed. This question is seeking recommendations for books, tools, software libraries, and more. It does not meet Stack Overflow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answere开发者_如何学Cd with facts and citations.

Closed 6 years ago.

Improve this question

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:

(([.#]?[a-zA-Z_-0-9]+\ *)+\{([a-zA-Z-])+\ *\:[^;]+;\})+

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.


You can run it through the w3 css validator: http://jigsaw.w3.org/css-validator/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜