I have a parent folder column in some panes views, and use the expression below. The important part, the RE, is in
red. The rest is just MC.
Regex([Filename (path)], /#
([^\\]+)\\$#/, 1)
( | Start of memory capture. |
[^\\] | A character class, matches any one of the listed characters; but a leading ^ negates to mean NOT any of the listed characters (i.e. NOT backslash). |
+ | 1 or more of the previous atom (i.e., one or more non-backslash characters). |
) | End of memory capture. |
\\ | A backslash character (which needs to be escaped, since \ is the escape char in RE. |
$ | Matches at the end of the line. |
Thus, for a [Filename (path)] such as:
C:\some\happily\nested\
parent\the RE will match the red part. Only the non-backslash stuff is remembered though, and is output by the 1 parameter in Regex(). It's almost easier to see how it works backwards, since we force anchoring at the end of the string. From the end of the string, going right-to-left, a backslash is matched, and then a bunch of non-backslash characters, until the RE must stop at the backslash between the d and p.