65535)) { return false; } // Validate path (reject illegal characters: < > { } | \ ^ `) if (!empty($matches[6]) && preg_match('/[<>{}|\\\^`]/', $matches[6])) { return false; } return true; } // If not hierarchical, check non-hierarchical URIs if (preg_match($nonHierarchicalPattern, $uri, $matches) === 1) { $scheme = strtolower($matches[1]); // Extract the scheme // Special case: `mailto:` must contain a **valid email address** if ($scheme === 'mailto') { return preg_match($emailPattern, $matches[2]) === 1; } return true; // Valid non-hierarchical URI } return false; } }