Is it possible to get folder name from a URL?
For example,
https://inside.nov.com/wh/pc/testSourceLib/Folder Z/SubFolder Z1/Copy files from one Document Library to another using Nintex Workflow _ My Learnings.pdf
where
https://inside.nov.com/wh/pc/
is the Web URLtestSourceLib
is the library nameFolder Z/Subfolder z1
is the folder nameI need to extract /Folder Z/Subfolder z1
from the above URL.
I tried ([^\/]*)$
and it gives me the file name Copy files from one Document Library to another using Nintex Workflow _ My Learnings.pdf
.
You can use a lookahead based regex with the Extract option:
/[^/]+/[^/]+(?=/[^/]*$)
See the regex demo
Pattern details:
[^/]+
- 1 or more characters other than /
...(?=/[^/]*$)
- followed with /
, zero or more characters other than /
([^/]*
) and then the end of string ($
). The construct is a positive lookahead that is a zero-width assertion that does not consume the text (not putting it into the returned match) that requires some text to the right of the current location in the string.To shorten the pattern a bit, you may wrap the /[^/]+
subpattern with a non-capturing group and apply a limiting quantifier on it:
(?:/[^/]+){2}(?=/[^/]*$)
See another demo