(?:[[:print:]]{2,}://)*)'; // Optional root prefix. $regex .= '(?(?:[[:alpha:]]:/|/)?)'; // Actual path. $regex .= '(?(?:[[:print:]]*))$%'; $parts = []; if (!preg_match($regex, $path, $parts)) { throw new InvalidArgumentException(sprintf('Path is not valid, "%s" given.', $path)); } if ('' !== $parts['root']) { return true; } return false; }