Forum: Ruby on Rails Backspace in strings and patterns

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
96146b7a23174e2e024c06a49f845bb8?d=identicon&s=25 Jeffrey L. Taylor (Guest)
on 2009-04-15 17:14
(Received via mailing list)
Interesting.  Not what I expected.  This is Ruby 1.8.6.

> irb
irb(main):001:0> str = "abx\bc"
=> "abx\bc"
irb(main):002:0> str.length
=> 5
irb(main):003:0> s = str.sub(/.\b/, '')
=> "ab\bc"
irb(main):004:0> s.length
=> 4
irb(main):005:0> s = str.sub(/.\x08/, '')
=> "abc"
irb(main):006:0> s.length
=> 3

Backspace character representation in ASCII, UTF-8, etc. is 8.

Bec38d63650c8912b6ba9b557fb953b9?d=identicon&s=25 Roger Pack (rogerdpack)
on 2009-04-15 17:20
Jeffrey L. Taylor wrote:
> Interesting.  Not what I expected.  This is Ruby 1.8.6.

ask ruby talk or core?
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-04-15 17:22
(Received via mailing list)
On Apr 15, 4:13 pm, "Jeffrey L. Taylor" <> wrote:
> Interesting.  Not what I expected.  This is Ruby 1.8.6.

Inside a rexexp, \b is not a backspace (except in a character class).
it means word boundary.

This topic is locked and can not be replied to.