Reputation: 148524
I have this urls:
C:\Projects\Ensure_Solution\GD_EServices_Web\App_WebReferences\GD_Eservices_Web_Service\GD_Eservices_Web_Service.wsdl
C:\Projects\Ensure_Solution\GD_EServices_Web\App_WebReferences\GD_Eservices_Web_Service\GD_Eservices_Web_Service.wsdl
I want to get the wsdl file name ( no leading slash)
I have succeeded with 2 solutions :
\\[^\\]+$
\\(.(?!\\))+$
But this returns the leading slash : http://regexr.com?32lvi
how can I enhance my regex return only the file ?
Upvotes: 0
Views: 183
Reputation: 160833
You just need to exclude the the leading slash in the regex.
var path = 'C:\\Projects\\Ensure_Solution\\GD_EServices_Web\\App_WebReferences\\GD_Eservices_Web_Service\\GD_Eservices_Web_Service.wsdl';
console.log(path.match(/[^\\]+$/));
And you could get it without regex, use split
, and get the last element with pop
:
console.log(path.split('\\').pop());
Upvotes: 1
Reputation: 442
This should do it:
([\w\d_-]*)\.?[^\\\/]*$
This thread has some examples for javascript.
Alternatively, you can so a string split on "\" to create an array and get the last one in the array.
Upvotes: 0
Reputation: 2463
This should work [^\\]+$
But for your case I'd prefer smth like string.split('/').pop()
(javascript) or array_pop(split('/', string))
(for php, I don't know language you are using) not regexp.
Upvotes: 1