.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 url
  • testsourcelib library name
  • folder z/subfolder z1 folder 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

enter image description here

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

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -