On Sun 6-Aug-06 12:51am -0600, A.J.Mechelynck wrote:
> Bill McCarthy wrote:
>> On Sat 5-Aug-06 10:42pm -0600, A.J.Mechelynck wrote:
>>> Bill McCarthy wrote:

>>>> Example 1:
>>>>
>>>>     :echo "<" . matchstr("  1.2345 ","[0-9.]") . ">"<CR>
>>>>     <1>
>>>>
>>>> Example 2:
>>>>     :echo "<" . matchstr("  1.2345 ","[0-9.]*") . ">"<CR>
>>>>     <>
>>>>
>>>> Why isn't the second exampe returning <1.2345>?
>>>>
>>>> Is there a better way of stripping spaces off a string?

>>> What you get is the first (leftmost) substring matching the pattern.
>>>
>>> In the first case the pattern matches exactly one dot or digit, and it
>>> matches the 1 at position 2.
>>>
>>> In the second case the pattern matches zero or more dots and digits, and
>>> it matches the null string at position 0.

>> That makes sense.

>>> If you had specified \+ as multi instead of * you would (IIUC) have got
>>> what you wanted.

>> I had:
>> 
>> Example 3:
>> 
>>     :echo "<" . matchstr("  1.2345 ","[0-9.]\+") . ">"<CR>
>>     <>
>> 
>> Example 4:
>> 
>>     :echo "<" . matchstr("  1.2345 ","\s*\zs[0-9.]\+") . ">"<CR>
>>     <>
>> 
>> Why did both of those fail?

> When giving a double-quoted string to a function as an argument,
> backslashes are interpreted before the function receives the argument.
> Use single quotes to pass the argument literally; or if you want double
> quotes, then double the backslashes.

I'm a little embarrassed because I know that :-(  This
correspondence will help reinforce the fact that strings
are interpreted as such first before they are passed on
while literals are not.

Thanks again!

-- 
Best regards,
Bill

Reply via email to