From: "tdrive (Stanislav Boldaev) via ruby-core" Date: 2025-10-28T09:10:07+00:00 Subject: [ruby-core:123560] [Ruby Bug#21651] replacing a string with one backslash with two backslashes Issue #21651 has been reported by tdrive (Stanislav Boldaev). ---------------------------------------- Bug #21651: replacing a string with one backslash with two backslashes https://bugs.ruby-lang.org/issues/21651 * Author: tdrive (Stanislav Boldaev) * Status: Open * ruby -v: 3.4.4 * Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- ruby 2.7.8p225 (2023-03-30 revision 1f4d455848) [x86_64-linux] ruby 3.4.4 (2025-05-14 revision a38531fd3f) +PRISM [x86_64-linux] ``` irb(main):002> "\\".gsub("\\", "\\\\") => "\\" irb(main):003> "\\".gsub("\\", "\\ \\") => "\\ \\" ``` The replacement is happening, as you can see from the version with the space, but why is the result so strange without the space? Similar code works fine in JS: ``` "\\".replace("\\", "\\\\") > '\\\\' ``` How to replace one backslash with two backslashes? -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/