有效的CSS和/或jQuery选择器的正则表达式 [英] Regular Expression for valid css and/or jQuery selector

查看:78
本文介绍了有效的CSS和/或jQuery选择器的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要这样的东西:

Regex validSelector = new Regex("^[.#a-zA-Z0-9_:[] ]+[,><a-zA-Z0-9_~=\"\":[] ]*$");

有人编写过用于验证jQuery或CSS选择器的正则表达式吗? (CSS3/jQuery1.4)

Has anybody written a regular expression for validating jQuery or CSS selectors? (CSS3/jQuery1.4)

或者,有人知道我在哪里可以找到正则表达式或正则表达式生成器来验证jQuery选择器?(或至少CSS选择器?)

Or, does anybody know where I can find a regex or regex generator to validate a jQuery selector?(or atleast CSS selectors?)

我尝试遍历John Resig的 sizzle.js 的代码和css的w3c文档(http ://www.w3.org/Style/CSS/),但最后头疼:(

I've tried going through the code of sizzle.js bu John Resig and the w3c docs for css (http://www.w3.org/Style/CSS/) but ended up havin a headache :(

我想问问是否有人已经为此编写或使用了一些代码段.

Thought i'd rather ask if any of you has already written or used some snippet for this.

谢谢!

推荐答案

CSS 3选择器的规范包含有关选择器语法的部分,您可以使用建立正则表达式.只需从 selector 开始,然后将每个变量替换为其生产,直到没有变量为止.

The Specification of CSS 3 Selectors has a section about the grammar of selectors that you can use to build the regular expression. Just start with selector and replace each variable with its production until there are no variables left.

这篇关于有效的CSS和/或jQuery选择器的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆