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.
Jeffrey L. Taylor (Guest)
on 2009-04-15 19: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.

Roger P. (Guest)
on 2009-04-15 19:20
Jeffrey L. Taylor wrote:
> Interesting.  Not what I expected.  This is Ruby 1.8.6.

ask ruby talk or core?
Frederick C. (Guest)
on 2009-04-15 19:22
(Received via mailing list)
On Apr 15, 4:13 pm, "Jeffrey L. Taylor" <removed_email_address@domain.invalid> 
> 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.