Regular Expressions 101

Community Patterns

PHP file path with wrappers

2

Regular Expression
PCRE (PHP <7.3)

/
^(?<wrappers>(?:[[:alpha:]][[:alnum:]]+://)*)(?<root>(?:[[:alpha:]]:/|/)?)(?<path>(?:[[:print:]]*))$
/

Description

Breaks file path up into wrappers, root, and path components. Understands both Windows (DOS) and Unix style paths. Wrappers and path components can be farther processed in code. Path component should support any visible Unicode character but not things like VT, HT or any other non-printing character. Most of the non-printable characters would also be allowed by file systems but are near impossible to enter.

Submitted by Dragonaire - 10 years ago