【问题标题】:ruby multiline grep in file文件中的 ruby​​ 多行 grep
【发布时间】:2013-05-20 21:47:49
【问题描述】:

我想找出所有 c++ 方法不以“NULL);”结尾的情况(NULL 和 之间的任意数量的空格)和 ;仍然应该让它匹配)。

我的代码是:

Dir['**/*'].select { |f| File.file?(f) } .map {
   |file| a=File.open(file).read 
   puts a.grep(/begin((?!NULL\s*\)\s*;).)+;/m)
}

我希望它匹配以下行:

begin

anything in here but a paren any number of spaces semicolon
);

但不匹配

begin 
somestuff that doesn't matter NULL);

不匹配

begin 
somestuff that doesn't matter 
NULL);

问题是我的代码目前只匹配单行。

Rubular 在这里: http://rubular.com/r/Ex9kmQLecH

【问题讨论】:

    标签: ruby grep multiline


    【解决方案1】:

    我最终做了一个 hacky 解决方案,我永远无法让多行的东西工作。

    Dir['**/*'].select { |f| File.file?(f) } .map {
       |file| a=File.open(file).read 
       a.gsub("\n"," ")
       a.gsub(";",";\n")
       puts a.grep(/begin((?!NULL\s*\)\s*;).)+;/)
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-15
      • 1970-01-01
      相关资源
      最近更新 更多