From: hanmac@... Date: 2018-05-28T14:01:37+00:00 Subject: [ruby-core:87279] [Ruby trunk Bug#14791] String.sub wrong parsing of replacement with capturing group Issue #14791 has been updated by Hanmac (Hans Mackowiak). read the Docs: ~~~ If replacement is a String it will be substituted for the matched text. It may contain back-references to the pattern's capture groups of the form "\d", where d is a group number, or "\k", where n is a group name. If it is a double-quoted string, both back-references must be preceded by an additional backslash. ~~~ it is explained what to do with the blackslashes. and how much do you need. ---------------------------------------- Bug #14791: String.sub wrong parsing of replacement with capturing group https://bugs.ruby-lang.org/issues/14791#change-72266 * Author: churib (Timo Grodzinski) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.3.3p222 (2016-11-21) [x86_64-linux-gnu] * Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN ---------------------------------------- ~~~ ruby irb(main):001:0> "abc".sub(/(b)/, '#\1#') # works => "a#b#c" irb(main):002:0> "abc".sub(/(b)/, '\\1') # doesn't works, should be "a\bc" => "abc" irb(main):003:0> "abc".sub(/(b)/, '\\\1') # doesn't works, should be "a\\bc" => "a\\1c" irb(main):004:0> "abc".sub(/(b)/, "\\1") # works => "abc" irb(main):005:0> "abc".sub(/(b)/, "\\\\1") # doesn't works, should be "a\bc" => "a\\1c" irb(main):006:0> "abc".sub(/(b)/, '\ \1') # works => "a\ bc" ~~~ -- https://bugs.ruby-lang.org/ Unsubscribe: