[BUG] greedy gsub

A

Ara.T.Howard

this looks like a bug to me:


~/eg/ruby > cat bug.rb

# greedy gsub works fine a bos
k1, p1 = '=foo', %r/^(=*)/
p(p1.match(k1).to_a)
p(k1.gsub(p1, '!'))

# greedy gsub fails at eos
k0, p0 = 'foo=', %r/(=*)$/
p(p0.match(k0).to_a)
p(k0.gsub(p0, '!'))

~/eg/ruby > ruby bug.rb

["=", "="]
"!foo"
["=", "="]
"foo!!"

~/eg/ruby > ruby -v
ruby 1.8.0 (2003-10-15) [i686-linux]



-a
--

ATTN: please update your address books with address below!

===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
| STP :: http://www.ngdc.noaa.gov/stp/
| NGDC :: http://www.ngdc.noaa.gov/
| NESDIS :: http://www.nesdis.noaa.gov/
| NOAA :: http://www.noaa.gov/
| US DOC :: http://www.commerce.gov/
|
| The difference between art and science is that science is what we
| understand well enough to explain to a computer.
| Art is everything else.
| -- Donald Knuth, "Discover"
|
| /bin/sh -c 'for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done'
===============================================================================
 
T

ts

A> this looks like a bug to me:

no, no

A> k0, p0 = 'foo=', %r/(=*)$/
A> p(p0.match(k0).to_a)
A> p(k0.gsub(p0, '!'))

first match because there is `=' at the end
second match because the empty patterm /=*/ match at end



Guy Decoux
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,781
Messages
2,569,616
Members
45,306
Latest member
TeddyWeath

Latest Threads

Top