Project

General

Profile

Actions

Bug #11793

closed

puts 'ab'.gsub('a', '\\+') - unexpected output

Added by burnson (William Burnson) over 8 years ago. Updated over 8 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin15]
[ruby-core:71976]

Description

Test case:

puts 'ab'.gsub('a', '\\+')

Expected output:

\+b

Actual output:

b

The way I understand gsub(pattern, replacement) when used with two string arguments is that it will perform a literal replacement, so it is quite unexpected that substituting with \+ removes the pattern entirely.

Doc: http://ruby-doc.org/core-2.2.3/String.html#method-i-gsub

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0