【问题标题】:finding selectors by specific css values with ack/grep regex使用 ack/grep 正则表达式通过特定 css 值查找选择器
【发布时间】:2012-04-17 04:37:18
【问题描述】:

我的 css 中有以下两个选择器,以这种格式布局:

// file1.css
#myId {
    margin-right:0;
    color:#f00;
}

// file2.css
#otherId { margin-right:0; color: #f00 }

我的目标是使用 ack/grep 搜索来获取选择器和颜色值。

如果我:

ack-grep '(^.*color:\s+\d+)'

我会得到:

file1.css
color:#f00;

file2.css
#otherId { margin-right:0; color: #f00 }

这个搜索对file2.css 很好,但对file1.css 不太好,可能是因为我使用^ 来匹配一行的开头.. 我如何始终匹配回一些css 的开头选择器(以 id 或类或标记名开头)?

更明显的是,我想要:

file1.css
#myId {margin-right:0; color:#f00;

file2.css
#otherId { margin-right:0; color: #f00 }

(并且选择器不一定必须是 ID。我应该匹配回之前的 } 还是文件的开头?

【问题讨论】:

标签: regex grep ack


【解决方案1】:

grep 和 ack 都不支持多行正则表达式:

ack FAQ

还有其他选择,例如 pcregrep。不过我会使用一些 CSS 解析器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-26
    • 2015-04-13
    • 1970-01-01
    • 1970-01-01
    • 2012-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多