search_file_replace方法正则表达式问题(Ruby)

时间:2017-06-19 09:41:58

标签: ruby

文件中有一行:

  

“配方[sometext :: anothertext]”,

并且它在开头有4个空格。

我需要将其替换为:

  

“配方[sometext :: anothertext_v2]”,

并留下那些空格。

我尝试了不同的方法而没有任何帮助。这是其中之一:

fe = Chef::Util::FileEdit.new("#{home_dir}/environment/#{environment}/" + node.run_state["hostname"] + "/node.json")
fe.search_file_replace(/\"recipe\[sometext::anothertext/, '"recipe[sometext::anothertext_v2')
fe.write_file

文件路径有问题吗?如何修复search_file_replace中的正则表达式?有什么想法吗?

0 个答案:

没有答案