Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE (PHP <7.3)

/
^([a-zA-Z]:(?=\\)|\\\\(?:[^\*:<>?\\\/|]+\\[^\*:<>?\\\/|]+|\?\\(?:[a-zA-Z]:(?=\\)|(?:UNC\\)?[^\*:<>?\\\/|]+\\[^\*:<>?\\\/|]+)))
/

Description

This extracts the "root" (e.g. drive) from a Windows path. See the unit tests for examples

Submitted by J5lx - 10 years ago