Regular Expressions 101

Community Patterns

Get parent folder and file name from full path

0

Regular Expression
PCRE (PHP <7.3)

/
\\(?=[^\\]*(?=\\(?=[^\\]*(?=\.(?![^\\]*(?=\\))))))(.*)(\..*)
/
gm

Description

This expr will get the parent folder and file name from a full path eg: c:\folder1\folder2\folder3\file1.txt returns folder3\file1.txt

Submitted by anonymous - 4 years ago