【发布时间】:2015-07-24 13:19:26
【问题描述】:
我正在尝试使用 bash 从 .css 文件中删除所有块 cmets。我有以下 sed 命令的正则表达式:
sed -r '/\/(\*)*(\s)?(\w)*|(\*)(\s)?(\w)*/d'
这可以很好地剥离块 cmets,例如:
/**
* This is a comment
*/
/* this is another comment */
但它也删除了 * Selector 的实例
* {
font-size: 10px;
...etc
}
如何更改当前的正则表达式以考虑这种特殊情况?还是我需要重写我的正则表达式?
编辑: 澄清一下,我将遇到的 cmets 类型:
/**
* This is a comment
*/
/* This is another comment */
/* This is also
valid
*/
/** "*/" as is { this } */
【问题讨论】:
-
一定要带sed吗?
-
最好,但我愿意接受建议,我愿意阅读 awk 或其他任何内容
-
/** "*/" as is { this } */:即使*/用双引号括起来,它也总是被视为一个结束序列。所以评论部分是/** "*/