[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

What does this regexp do?

Daniel DeLorme

10/2/2008 2:12:00 PM

I can't figure out what this does:
>> "1\n2\n3\n"[ /.\Z?/ ]
=> ""

I would expect it to output "1", just as:
>> "1\n2\n3\n"[ /.(\Z)?/ ]
=> "1"

Is this a bug?

--
Daniel

1 Answer

Mark Thomas

10/2/2008 2:49:00 PM

0

On Oct 2, 10:11 am, Daniel DeLorme <dan...@dan42.com> wrote:
> I can't figure out what this does:
>  >> "1\n2\n3\n"[ /.\Z?/ ]
> => ""
>
> I would expect it to output "1", just as:
>  >> "1\n2\n3\n"[ /.(\Z)?/ ]
> => "1"
>
> Is this a bug?

Neither one of those make any sense. An optional end-of-string means
nothing. That second one is the same as [/./]

-- Mark.