angularjs - Extract part of path from full path Javascript -


how can extract

pathb/pathc/pathd 

from

patha/pathb/pathc/pathd/data.json 

welcome third party library or plain javascript

in loader of webpack such ng-cache-loader, found able strip middle part of path specifying '//'.

from ng-cache-loader docs:

prefix can strip real directory name (use //):

require('ng-cache?prefix=public/*//*/templates!./far/far/away/path/to/mypartial.html') // => ng-include="'public/far/path/templates/mypartial.html'"   

i can't find code process path in ng-cache-loader source code. maybe can use same way did strip middle part of path?

i approached problem string parsing one, mzografski mentionned. can check working jsfiddle

code :

$scope.toextract = 'pathb/pathc/pathd'; $scope.test = 'patha/pathb/pathc/pathd/data.json';  $scope.extract = function(parttoextract, fullpath) {     var index = fullpath.indexof(parttoextract);     return(fullpath.substring(0, index) + fullpath.substring(index+parttoextract.length+1, fullpath.length)); };  $scope.extract($scope.toextract, $scope.test); 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -