Issue #12703 has been reported by Nathan LaVeck.

----------------------------------------
Bug #12703: String.gsub returns unexpected results with numeric match characters
https://bugs.ruby-lang.org/issues/12703

* Author: Nathan LaVeck
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
I'm unable to prepend a backslash to numeric group matches using gsub

~~~
irb(main):053:0> "z'z".gsub(/(')/, '\\1')
=> "z'z"
~~~

Expected Result

~~~
=> "z\'z"
~~~

Adding an extra backslash gives me this:

~~~
irb(main):056:0> "z'z".gsub(/(')/, '\\\1')
=> "z\\1z"
~~~


Tested on Ruby version 2.4.0



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>