0

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

enter image description here

how can I enhance my regex return only the file ?

Royi Namir
  • 144,742
  • 138
  • 468
  • 792

5 Answers5

1

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.

Vyacheslav Voronchuk
  • 2,403
  • 19
  • 16
1

Try with the negative look-ahead (?!\\)(.(?!\\))+$

Christoph
  • 50,121
  • 21
  • 99
  • 128
0x41ndrea
  • 385
  • 5
  • 23
1

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());
xdazz
  • 158,678
  • 38
  • 247
  • 274
0

Try this

\\[^\\]+$

Note:that means try with only one leading backslash

Christoph
  • 50,121
  • 21
  • 99
  • 128
Flow
  • 35
  • 2
0

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.

Community
  • 1
  • 1
Tony T
  • 442
  • 3
  • 9