Basically, I provide an easy way to use sed command for the user, without thinking about the complexity of that command.
So when the user is calling that function, when I get the user entry, I would like to perform a test on that entry to escape all special characters sed can badly interpret.
It’s for that function:
def replaceTextAllFilesRecursivelyNamed(path : String, filename : String, text : String, newText : String)
regex = //
replacement = ""
requestedCommands = <<-CMD
find -name #{filename} -exec sed -i 's/#{text.gsub(regex,replacement)}/#{newText.gsub(regex,replacement)}/' {} \\;
CMD
process = runSystemCommand(requestedCommands)
if !process.success?
Ism.notifyOfRunSystemCommandError(requestedCommands)
Ism.exitProgram
end
end
I guess you add one more \ in your replacement string. (if you prefer replace it yourself instead of use Regex.escape), you need double \ to output the raw \ in the string, and use %q to avoid explain the \ as escaped char.
I will probably to move to your solution, because I noticed on my last experiment that Regex.escape don’t do exactly what I want I just make the generated system unusable. I need to fix that