[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

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

RichardOnRails

8/3/2008 5:04:00 PM

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
1 Answer

RichardOnRails

8/3/2008 6:13:00 PM

0

On Aug 3, 1:03 pm, RichardOnRails
<RichardDummyMailbox58...@uscomputergurus.com> wrote:
> 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