Template for matching file path

Could you tell me the grep pattern to match the following file path:

../any_directoryname/filename.txt

I only know the file name. any_directorynamekeeps changing.

Thanks in advance,

Hi

John

+3
source share
4 answers

Try the following:

\.\./[^/]+/filename.txt

This assumes only one directory. If it could be more, try

\.\./[^\r\n]+/filename.txt 
+4
source

try this regex

^\.\.\/[\w]+\/[\w\.]+$
0
source

,

str_replace('/filename.txt', '', $full_path);

, , ( , - , , ), , t , .

0
source

What about...

(Perl answer ...)

For a given path / file name in the form:

$fullPath = /dir/dir/dir/filename

($path, $file) = $fullPath =~ m/(^\/.*\/)(\S+$)/;

What puts

$path = /dir/dir/dir/...
$file = filename
0
source

All Articles