From: t_leitner@... Date: 2015-05-11T08:48:38+00:00 Subject: [ruby-core:69121] [Ruby trunk - Bug #11132] [Open] String#sub and character sequence \' in replacement string Issue #11132 has been reported by Thomas Leitner. ---------------------------------------- Bug #11132: String#sub and character sequence \' in replacement string https://bugs.ruby-lang.org/issues/11132 * Author: Thomas Leitner * Status: Open * Priority: Normal * Assignee: * ruby -v: ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux] * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN ---------------------------------------- Hi, I don't know if this is intentional but substitution of `\'` and `` \` `` in the replacement string was rather unexpected for me: ~~~ 2.2.2 :001 > "this is a test".sub(/this/, "some text \\'") => "some text is a test is a test" ~~~ I would have expected the following result: ~~~ => "some text \\' is a test" ~~~ The documentation says nothing about this, just that back-references can be used (i.e. `\\d` or `\\k`). A work-around is escaping the escape character: ~~~ 2.2.2 :001 > "this is a test".sub(/this/, "some text \\\\'") => "some text \\' is a test" ~~~ Thanks! -- https://bugs.ruby-lang.org/