[英]What is a grep pattern for matching lines?
I am trying to find all cases in my test suite where one-line it
methods are used back to back.我试图在我的测试套件中找到所有使用单行it
方法的案例。 Basically, I'm looking for files that have lines like these:基本上,我正在寻找具有以下行的文件:
it { expect(some_stuff).to be_true }
it { expect(other_stuff).to be_false }
but not this:但不是这个:
it { expect(some_stuff).to be_true }
# a bunch of other stuff
it { expect(other_stuff).to be_true }
and can't quite figure out the pattern.并且无法完全弄清楚模式。 I have tried:我努力了:
> grep it.\{*\}\n*it ./test/directory -lR
# and
> grep it.\{*\}\n*it.\{*
which returns nothing, but I know there is at least one matching file.它什么都不返回,但我知道至少有一个匹配的文件。 Does anyone know how to create the pattern I'm looking for?有谁知道如何创建我正在寻找的模式?
The pattern you might be looking for is /(?:it.*$)\n(?:it.*$)/
您可能正在寻找的模式是/(?:it.*$)\n(?:it.*$)/
But the problem you might be facing with grep
or egrep
is that this utility searches through a file single line at a time, so it doesn't support let say \n
in a regular expression.但是您可能在使用grep
或egrep
时遇到的问题是,此实用程序一次只搜索一行文件,因此它不支持在正则表达式中使用\n
。
So you might want to look for other options than just grep
.因此,您可能想寻找除grep
之外的其他选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.