[ruby-core:77052] [Ruby trunk Bug#12703] String.gsub returns unexpected results with numeric match characters
From:
nlaveck@...
Date:
2016-08-25 02:24:38 UTC
List:
ruby-core #77052
Issue #12703 has been updated by Nathan LaVeck.
ruby -v set to ruby 2.4.0dev (2016-08-25 trunk 56006)
----------------------------------------
Bug #12703: String.gsub returns unexpected results with numeric match characters
https://bugs.ruby-lang.org/issues/12703#change-60276
* Author: Nathan LaVeck
* Status: Open
* Priority: Normal
* Assignee:
* ruby -v: ruby 2.4.0dev (2016-08-25 trunk 56006)
* 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>