I want to extract the last part of the path. For eg if my path is:
\\abc.ksiw.com\POP-K-DRIVE\project-app\cname\554789A
I want 554789A
as output.
I tried with regexp_extract(col, '[\\w ] $',0)
but that does not work. Is there a better way to do this?
CodePudding user response:
This works:
regexp_extract(col,'([^\\\\]*)$',1)
Backslash is special character both in Hive and in regex.
Four back slashes is used to represent a single backslash in regex.
If you want to test on literal constant, use two backslashes instead of one in literal and four in regexp:
select regexp_extract('\\\\abc.ksiw.com\\POP-K-DRIVE\\project-app\\cname\\554789A','([^\\\\]*)$',1);
Result:
554789A
(\\w )$
also works:
regexp_extract(col,'(\\w )$',1)