[PATCH] was - Re: substring by range parameter (bug?)

When I found that on the first time, I thought that it is a bug.
But after I try and I think now this is maybe a nice feature to get the empty string.
(As described on my conclusion).

So, I agree with Mark, this strange behaviour allow you to get the empty string. maybe nice to leave as it like now.

Here list almost all ways to get the empty substring of "ab".
(There are 3, "^a^b^", ^ shows where the empty substring locate at)

The !! note that the case is supprise to me at fist time.

# using [off,len] to get them:
s="ab"; s[0,0]="xxx"; s #=> "xxxab"
s="ab"; s[1,0]="xxx"; s #=> "axxxb"
s="ab"; s[2,0]="xxx"; s #=> "abxxx" !!
s="ab"; s[-1,0]="xxx"; s #=> "axxxb"
s="ab"; s[-2,0]="xxx"; s #=> "xxxab"

# using [/regexp/] to get them:
s="ab"; s[/^/]="xxx"; s #=> "xxxab"
s="ab"; s[/(?=b)/]="xxx"; s #=> "axxxb"
s="ab"; s[/$/]="xxx"; s #=> "abxxx"

# using [range] to get them:
s="ab"; s[-1..-2]="xxx"; s #=> "axxxb" !!
s="ab"; s[-2..-3]="xxx"; s #=> "xxxab" !!
s="ab"; s[1..0]="xxx"; s #=> "axxxb" !!
s="ab"; s[2..1]="xxx"; s #=> "abxxx" !!

# using [string] to get it (in this case, you can only get the specific one)
s="ab"; s[""]="xxx"; s #=> "xxxab"

BTW: Q: RegExp exists lookbehind meta char? opposite of lookahead.

···

_________________________________________________________________
Don’t just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/