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

R

RichardOnRails

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
 
R

RichardOnRails

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

Hi All,

The answer is my mistake :-(
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
 

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

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,244
Members
46,838
Latest member
KandiceChi

Latest Threads

Top