From: nobu@... Date: 2015-05-11T12:43:07+00:00 Subject: [ruby-core:69123] [Ruby trunk - Bug #11132] String#sub and character sequence \' in replacement string Issue #11132 has been updated by Nobuyoshi Nakada. It's a spec, but seems there is no docs about it. This is a documentation issue. ---------------------------------------- Bug #11132: String#sub and character sequence \' in replacement string https://bugs.ruby-lang.org/issues/11132#change-52379 * 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/