Project

General

Profile

Actions

Bug #12703

closed

String.gsub returns unexpected results with numeric match characters

Added by nlaveck (Nathan LaVeck) over 7 years ago. Updated over 7 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.0dev (2016-08-25 trunk 56006)
[ruby-core:77051]

Description

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

Actions

Also available in: Atom PDF

Like0
Like0Like0