Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex remove last folder from path

Tags:

regex

Using Regex I need to remove the last folder from a path:

Example : C:\Temp\Dir1\

Output : C:\Temp\

Please don't suggest that I can do this with c# or other programming language. I really do need the regex for this.

Thanks in advance for the help.

like image 384
sianabanana Avatar asked Jun 29 '12 09:06

sianabanana


1 Answers

Replace

[^\\]+\\?$

by nothing. This works for paths like C:\Temp\Dir1 (no trailing backslash) as well. It fails for the root directory of a drive.

like image 154
Joey Avatar answered Nov 15 '22 10:11

Joey