ace007
ace007

Reputation: 577

Regex Get path name from full path

can anyone give me a few examples of getting the path from a full path..e.g

c:\aaa\bbb\c cc\file.exe

to

c:\aaa\bbb\c cc\

more than 1 example method would be cool but must be regex only, this is for a language called ICI but it has similar regex to perl and other such language this is why I need a few examples, atleast one will work better than the other and i can modify it.

thanks!

Upvotes: 0

Views: 1086

Answers (3)

Civa
Civa

Reputation: 2176

try this pattern it will help full

[^\\]+\\

Upvotes: 0

munch1324
munch1324

Reputation: 1148

Here is a basic example of an inverse regex (finds the filename). Just use the substring before the start to get the path.

[\w]*[.][\w]*$

And the path only:

.*[\\]

Upvotes: 1

frickskit
frickskit

Reputation: 624

Group (1) will give you c:\aaa\bbb\c cc with this

(.*)\\\w*\.

You can use

(.*\\)\w*\.

if you want to capture the last \

Upvotes: 1

Related Questions