我想为任何不遵循以下模式之一的左大括号创建一个匹配模式:
{\n\n
{\s*\/\/.*\n\(\s*\/\/.*\)\?\n
更普遍的问题是在工作中突出显示违反编码规范的行为,这会在后面强制一个空行{
澄清一下,我正在寻找这个来捕获如下代码:
if (foo) {
this_is_bad____no_blank_line_above();
} else {this_is_worse();}
while (1) { //This comment is allowed
//This one too
theres_nothing_wrong_with_this();
}
if (foo) {
....//<-- Ideally we could mark this as bad, due to the spaces here
otherwise_perfectly_good();
}
我真正需要的是:{\(\n\n\|\s*\/\/.*\n\(\s*\/\/.*\)\?\n\)\!
其中虚构符号\!
表示“与这两个选项中的任何一个都不匹配”。我看到了一种对单个字符执行此操作的方法,但对于更长的字符串却没有。