From: eregontp@... Date: 2020-09-24T16:48:46+00:00 Subject: [ruby-core:100111] [Ruby master Bug#17184] No stdlib function to perform simple string replacement Issue #17184 has been updated by Eregon (Benoit Daloze). znz (Kazuhiro NISHIYAMA) wrote in #note-8: > You can use `gsub("SCRIPT") { "replacement" }`. I forgot about this form for this purpose. I find it really not intuitive for replacing strings. A block is typically useful for more custom/complicated logic, but here ironically it has more simple semantics than the replacement String argument. ---------------------------------------- Bug #17184: No stdlib function to perform simple string replacement https://bugs.ruby-lang.org/issues/17184#change-87679 * 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: