css - 解释查找 CSS 注释的正则表达式

标签 css regex

我发现这个正则表达式代码可以在 w3.org 的 CSS grammar 中找到评论页面。

\/\*[^*]*\*+([^/*][^*]*\*+)*\/

它很长,有点难以理解。我只是把

\/\*.*\*\/

查找评论,但是当我在 RegexPal 中测试它时它找到单行注释而不是多行注释,而原始正则表达式可以找到所有类型的注释。

我不明白这是什么

+([^/*][^*]*\*+)*

原始正则表达式中的部分。谁能给我解释一下?

最佳答案

token 解释:

\/    <- an escaped '/', matches '/'
\*    <- an escaped '*', matches '*'
[^*]* <- a negated character class with quantifier, matches anything but '*' zero or more times
\*+   <- an escaped '*' with quantifier, matches '*' once or more
(     <- beginning of group 
[^/*] <- negated character class, matches anything but '/' or '*' once
[^*]* <- negated character class with quantifier, matches anything but '*' zero or more times
\*+   <- escaped '*' with quantifier, matches '*' once or more
)*    <- end of group with quantifier, matches group zero or more times
\/    <- an escaped '/', matches '/'

Regex Reference

Analysis on Regexper.com

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

相关文章:

CSS渐变边框:after

javascript - 加载特定的 Bootstrap 选项卡

python - 如何在 python 中搜索一系列行?

java Regex - 拆分但忽略引号内的文本?

C# - 使用正则表达式将数据排序到/从列表框

JavaScript 正则表达式

javascript - 为什么我的按钮在表单内时不会更改浏览器的位置?

html - 宽度为 100% 高度为 100% 的 div 上的边距位于另一个宽度为 100% 高度为 100% 的 div 内

html - 模拟stackoverflow之类的Tab效果

javascript - 正则表达式匹配不带字符的单词