From: sheerun@... Date: 2020-09-24T15:45:04+00:00 Subject: [ruby-core:100109] [Ruby master Bug#17184] No stdlib function to perform simple string replacement Issue #17184 has been updated by sheerun (Adam Stankiewicz). Nice, it actually suits me. I'll leave this issue open though, because I agree with what Benoit said above ---------------------------------------- Bug #17184: No stdlib function to perform simple string replacement https://bugs.ruby-lang.org/issues/17184#change-87677 * Author: sheerun (Adam Stankiewicz) * Status: Open * Priority: Normal * ruby -v: ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-darwin19] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN ---------------------------------------- I have following simple `build.rb`: ```rb template = File.read('template.vim') script = File.read('script.vim') File.write('app.vim', template.gsub("SCRIPT", script)) ``` And then following `template.vim`: ```vim " some header SCRIPT ``` Plus following `script.vim`: ```vim if g:something =~ "\s\+" echo 'g:something is empty' endif ``` I'd expect that the script above produces `app.vim` with following contents: ```vim " some header if g:something =~ "\s\+" echo 'g:something is empty' endif ``` Unfortunately it produces following: ```vim " some header if g:something =~ "\s" echo 'g:something is empty' endif ``` It's probably because gsub interprets `\+` in script as back-reference. I tried to find replacement function in ruby that just replaces one string with something else, without interpreting replacement in any way, but surprisingly I haven't found any.. Am I mistaken? -- https://bugs.ruby-lang.org/ Unsubscribe: