.net - regular expression to get folder name from URL -
is possible folder name url?
for example,
https://inside.nov.com/wh/pc/testsourcelib/folder z/subfolder z1/copy files 1 document library using nintex workflow _ learnings.pdf where
https://inside.nov.com/wh/pc/web urltestsourceliblibrary namefolder z/subfolder z1folder name
i need extract /folder z/subfolder z1 above url.
i tried ([^\/]*)$ , gives me file name copy files 1 document library using nintex workflow _ learnings.pdf.
you can use lookahead based regex extract option:
/[^/]+/[^/]+(?=/[^/]*$) see regex demo
pattern details:
[^/]+- 1 or more characters other/...(?=/[^/]*$)- followed/, 0 or more characters other/([^/]*) , end of string ($). construct positive lookahead zero-width assertion not consume text (not putting returned match) requires text right of current location in string.
to shorten pattern bit, may wrap /[^/]+ subpattern non-capturing group , apply limiting quantifier on it:
(?:/[^/]+){2}(?=/[^/]*$) see another demo

Comments
Post a Comment