Regular Expressions 101

Community Patterns

Shorten file path with /../

2

Regular Expression
PCRE (PHP <7.3)

/
(?:^|(?<=\/)) (?:[^\s.\/]+|\.(?!\.\/))++ \/\.\.\/
/
gmix

Description

Example usage: $Path = preg_replace('/(?:^|(?<=/))(?:[^\s./]+|.(?!./))++/..//i', '', $Path);

Submitted by Mr.Deek & +OnlineCop - 8 years ago