Look-around not working in ruby 1.9.0 or my mistake?

Hi,

I just installed ruby 1.9.0 (2008-07-25 revision 18217) [i386-mswin32]
in order get Ruby look-behind functionality. I expected the following
snippet to insert a substring, but it did nothing:

Ruby:
printf(“item = “%s”\n”, item) if $DEBUG
printf(“item basename = “%s”\n”, File.basename(item)) if $DEBUG
item.sub!( /(?<=Investment-\d\d.\d\d)(?=-)/, ‘.2008’)
printf(“new item base = “%s”\n”, File.basename(item)) if $DEBUG

Output:
item = “K:___Investment\2008-Trades\Investments-06.19-2100.xls”
item basename = “Investments-06.19-2100.xls”
new item base = “Investments-06.19-2100.xls”

Expected:
new item base = “Investments-06.19.2008-2100.xls”

Any idea of what’s wrong?

TIA,
Richard

On Aug 3, 1:03 pm, RichardOnRails
[email protected] wrote:

printf(“new item base = "%s"\n”, File.basename(item)) if $DEBUG

TIA,
Richard

Hi All,

The answer is my mistake :frowning:
I left the “s” out of “investments”, i.e the sub. statement should
have been:

item.sub!( /(?<=Investments-\d\d.\d\d)(?=[-])/, ‘.2008’)

I apologize for posting a false alarm.

Best wishes,
Richard