簡體   English   中英

文件中的ruby multiline grep

[英]ruby multiline grep in file

我想找到所有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

我最終做了一個駭人聽聞的解決方案,但我永遠無法使多行工具正常工作。

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*;).)+;/)
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM