Backspace in strings and patterns


#1

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
irb(main):007:0>

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

Jeffrey


#2

Jeffrey L. Taylor wrote:

Interesting. Not what I expected. This is Ruby 1.8.6.

ask ruby talk or core?
-=r


#3

On Apr 15, 4:13 pm, “Jeffrey L. Taylor” removed_email_address@domain.invalid 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.

Fred