I have filesystem-like (but numerical) path of arbitrary length which I need to canonicalize to a fixed depth (2 or 3). Basically, I want this result:
/01/02/007/008 -> 01/02/007
/01/02/007 -> 01/02/007
/01/02 -> 01/02/NA
/01 -> 01/NA/NA
I want to do with using Oracle's regexp_replace()
function, which apparently impelements the extended POSIX regexp standard.
What I have so far is this: regexp_replace(path,'/([^/]+(/[^/]+)?).*','\1');
But I'm having trouble with the NA
part.