Hello,
I recently downloaded ruby 1.8.0 p3, (2003-06-23) [i686-linux], and
tried it on some code that chopped trailing spaces from a string using
gsub(/\s*$/, “”). I’m seeing some odd behavior and was hoping someone
could shed some light on what’s happening.
In 1.6.7 the code above did what I expected. However, in 1.8.0p3 it
seems to double the string if the string doesn’t end in a space.
#does what I expected in 1.6 and 1.8
irb(main):004:0> " TEST “.gsub(/\s*$/, “”)
=> " TEST”
very odd (at least to me) in 1.8.0p3
irb(main):005:0> " TEST .".gsub(/\s*$/, “”)
=> " TEST . TEST ."
Where does this repeat come from? If I change the * to a + it fixes my
problem but I was hoping someone could help explain why it’s happening.
While looking into this I’ve noticed that there seems to be something
special about 2 repeats.
Regardless of how many trailing spaces I add two Ps are always
appended. It seems that one matches all the spaces and then one matches
the zero length string that’s the end itself since a string without
trailing spaces puts in one P. Is the $ getting used twice in this
match?
I’d appreciate any explanations or help.
thank you,
Paul
I don’t know what the problem is, but you should probably be using
gsub(/\s+$/,‘’) anyway :o)
-Kurt
···
On Tue, Jul 22, 2003 at 03:36:56AM +0900, Paul Rubel wrote:
Hello,
I recently downloaded ruby 1.8.0 p3, (2003-06-23) [i686-linux], and
tried it on some code that chopped trailing spaces from a string using
gsub(/\s*$/, “”). I’m seeing some odd behavior and was hoping someone
could shed some light on what’s happening.
In 1.6.7 the code above did what I expected. However, in 1.8.0p3 it
seems to double the string if the string doesn’t end in a space.
#does what I expected in 1.6 and 1.8
irb(main):004:0> " TEST “.gsub(/\s*$/, “”)
=> " TEST”
very odd (at least to me) in 1.8.0p3
irb(main):005:0> " TEST .“.gsub(/\s*$/, “”)
=> " TEST . TEST .”
Where does this repeat come from? If I change the * to a + it fixes my
problem but I was hoping someone could help explain why it’s happening.
While looking into this I’ve noticed that there seems to be something
special about 2 repeats.
Regardless of how many trailing spaces I add two Ps are always
appended. It seems that one matches all the spaces and then one matches
the zero length string that’s the end itself since a string without
trailing spaces puts in one P. Is the $ getting used twice in this
match?
I’d appreciate any explanations or help.
thank you,
Paul