css - CSS SelectorText 的正则表达式

标签 css regex

我正在尝试编写一个 regex 以从 css selectorText 中提取节点 ID 和类。

例如:

.linear *, .test-in *, .test-out *, .test *, .test-in-out.casanova#casanova * > #test22

我需要一个 regex 来仅提取类和 ids:

linear , test-in , test-out , test , test-in-out , casanova , casanova , test22

所以我需要一个 regex 来匹配第一次出现时以 ./# 开头并以 space/./# 结尾的任何字符串对于他们中的任何一个。

我设法创建了 this :

(?:^|[\.]).*?([^\s]+(?!\.))

但是如您所见,它无法正常工作。

最佳答案

(?:\.|\#)([_a-zA-Z0-9-\:]*)(?:\b|<|>|\+|~|\[)

此正则表达式还将捕获一些无效的 css 选择器,例如 -_--__abc。但就您而言,我相信这会解决您的问题。

关于css - CSS SelectorText 的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51239445/

相关文章:

css - 是全局定义位置:relative to page container a good practice?

html - DIV 中 TABLE 的 CSS 布局问题

php - preg_split 由空格和制表符外引号

Java 正则表达式构建

javascript - 正则表达式将 <h[n]> 替换为 <h2> 输出不是预期的

Java RegEx 查找方法名称

javascript - 网页动画背后的技术是什么?

css - 我该怎么做才能使位置 :fixed work well

html - 使用一致的 CSS 和 HTML 创建 HTML 模块

python 重新: no such group