I don't understand how to get 'nth match of pattern starting at end of string'. I've read, but cannot apply.
The column I'm working with is directory path names that look typically like:
I:\044\LOGFILE\aw_34\
I want to pull out the last directory name, and the 2nd to last. Using regexp_substr I am able to get the last directory using
SELECT REGEXP_SUBSTR(col_name, '\\[^\]+\\$')
I think what I'm asking here is: 'beginning at the end of the value in col_name, return the first instance of 1 or more non-backslash characters that lie between two backslashes'.
However, I'm not able to use any sensible combination of option parameters to get just the second folder name ('\LOGFILE\' in this example). I've tried:
SELECT REGEXP_SUBSTR(col_name, '\\[^\]+\\$', 1, 2)
returns NULL. It seems I'm not actually asking 'start at the end of the string and find the second occurrence of the pattern'. So, I've resorted to matching the pattern of the two last folders:
SELECT REGEXP_SUBSTR(col_name, '\\[^\]+\\[^\]+\\$')
then, wrapping this expression in a 2nd regex to get a match on a single folder beginning at the front.
That works, but doesn't help me understand the basic error in using
REGEXP_SUBSTR(col_name, '\\[^\]+\\$', 1, 2)
or another more 'direct' way of pulling out just the match I need ('\LOGFILE\' in this example). What's wrong?