Issue #8136 has been reported by alexeymuranov (Alexey Muranov). ---------------------------------------- Bug #8136: gsub strange behavior when substituting "\\'" https://bugs.ruby-lang.org/issues/8136 Author: alexeymuranov (Alexey Muranov) Status: Open Priority: Normal Assignee: Category: Target version: ruby -v: 2.0.0 =begin s = "\\'" # => "\\'" print s # \' "foo".gsub("f", s) # => "oooo" Can anybody please explain to me why it works like this? Is this a bug? =end
on 2013-03-21 11:06
on 2013-03-21 13:58
Issue #8136 has been updated by Eregon (Benoit Daloze). Seems like \' is interpreted as $' ($POSTMATCH) which is in this case 'oo'. ---------------------------------------- Bug #8136: gsub strange behavior when substituting "\\'" https://bugs.ruby-lang.org/issues/8136#change-37792 Author: alexeymuranov (Alexey Muranov) Status: Open Priority: Normal Assignee: Category: Target version: ruby -v: 2.0.0 =begin s = "\\'" # => "\\'" print s # \' "foo".gsub("f", s) # => "oooo" Can anybody please explain to me why it works like this? Is this a bug? =end
on 2013-03-30 22:38
Issue #8136 has been updated by nobu (Nobuyoshi Nakada). Category set to doc Status changed from Open to Closed This is one of most frequently asked questions. Though I can't remember a pointer to good explanation, someone would know it. ---------------------------------------- Bug #8136: gsub strange behavior when substituting "\\'" https://bugs.ruby-lang.org/issues/8136#change-38059 Author: alexeymuranov (Alexey Muranov) Status: Closed Priority: Normal Assignee: Category: doc Target version: ruby -v: 2.0.0 =begin s = "\\'" # => "\\'" print s # \' "foo".gsub("f", s) # => "oooo" Can anybody please explain to me why it works like this? Is this a bug? =end
on 2013-03-31 13:13
Issue #8136 has been updated by alexeymuranov (Alexey Muranov). Excuse me, nobu, i have not understood, how can i replace something with a backslash followed by single quote? ---------------------------------------- Bug #8136: gsub strange behavior when substituting "\\'" https://bugs.ruby-lang.org/issues/8136#change-38062 Author: alexeymuranov (Alexey Muranov) Status: Closed Priority: Normal Assignee: Category: doc Target version: ruby -v: 2.0.0 =begin s = "\\'" # => "\\'" print s # \' "foo".gsub("f", s) # => "oooo" Can anybody please explain to me why it works like this? Is this a bug? =end
on 2013-04-01 09:58
Issue #8136 has been updated by nobu (Nobuyoshi Nakada).
You need more escapes.
"foo".gsub("f", "\\\\'")
----------------------------------------
Bug #8136: gsub strange behavior when substituting "\\'"
https://bugs.ruby-lang.org/issues/8136#change-38077
Author: alexeymuranov (Alexey Muranov)
Status: Closed
Priority: Normal
Assignee:
Category: doc
Target version:
ruby -v: 2.0.0
=begin
s = "\\'" # => "\\'"
print s # \'
"foo".gsub("f", s) # => "oooo"
Can anybody please explain to me why it works like this? Is this a bug?
=end
on 2013-04-01 14:14
Issue #8136 has been updated by alexeymuranov (Alexey Muranov). nobu (Nobuyoshi Nakada) wrote: > =begin > You need more escapes. > > "foo".gsub("f", "\\\\'") > =end Thank you, i have not read the documentation carefully. It is still a bit strange to me that a replacement string is not taken literally by default. ---------------------------------------- Bug #8136: gsub strange behavior when substituting "\\'" https://bugs.ruby-lang.org/issues/8136#change-38081 Author: alexeymuranov (Alexey Muranov) Status: Closed Priority: Normal Assignee: Category: doc Target version: ruby -v: 2.0.0 =begin s = "\\'" # => "\\'" print s # \' "foo".gsub("f", s) # => "oooo" Can anybody please explain to me why it works like this? Is this a bug? =end
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.