文件中有一行:
“配方[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中的正则表达式?有什么想法吗?