To get \ in a regex you need to escape it to \\, since the slash is reserved in the regex. Then each slash needs to be escaped again to be used in a java string. Hence \\\\. Painful, yes.
On Fri, Sep 7, 2012 at 2:06 PM, Danfeng Li <[email protected]> wrote: > Hi, > > I'm little bit puzzled about REPLACE when there is backslash involved. > > I want to replace all the "dir" in the string with "\\test\sub", > > After a lot of try and error, I finally got it done, but I'm not sure why > it is the case. Here's my code > > A = load 'a.txt' as (name:chararray); > B = foreach A generate REPLACE(name,'dir','\\\\\\\\test\\\\sub'); > dump B; > > The thing I'm confused about is why do I need to use "\\\\" in order to > generate a "\", can anyone explain the reason? I'm using pig 0.9.1. > > Thanks. > > Dan > -- *Note that I'm no longer using my Yahoo! email address. Please email me at [email protected] going forward.*
