On Sat 25-Nov-06 2:17pm -0600, you wrote:

> On 11/25/06, Bill McCarthy <[EMAIL PROTECTED]> wrote:
>>     let a = 'a\b'
>>     echo substitute(a,'\','/','')

> Backslash is special not only for "...". It is special in regex.
> Thus when you want to match literal [\] in regex inside
> '', you double it:
>     echo substitute(a,'\\','/','')

Right, I need to think of the two operations, how the single
or double quote deals with the backslash AND how the result
is treated as a regex.

But the example I gave:

    echo substitute(a,'\','/','')

actually works.  The regex process appears to treat a single
backslash as a special case - it treats it like a pair of
backslashes.

On the other hand, if I want to replace \b with /b then,
using a literal, I clearly need that second backslash:

    echo substitute(a,'\\b','/b','')

Likewise, if I want to eliminate an embedded <CR>, I can use
any of '\n', "\n" or "\\n" as the pattern of a substitute().
[The first and third pass on a literal \n which is
translated by the regex process.  The second passes on a
literal EOL with is used by the regex process without
translation.]

Thanks!

-- 
Best regards,
Bill

Reply via email to