How can the regex pattern be modified to better handle URLs with query parameters like ?id=23&user=franz?

The regex pattern can be modified to better handle URLs with query parameters by including the characters "?" and "=" in the pattern to specifically match query parameters. This can be achieved by adding "\?" to match the question mark and "=[^&\s]*" to match the parameter key-value pairs. This modification ensures that the regex pattern accurately captures URLs with query parameters like "?id=23&user=franz".

$url = "https://www.example.com/page?id=23&user=franz";
$pattern = '/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?(\?[\w=&%]*)?$/i';

if (preg_match($pattern, $url)) {
    echo "URL matches the pattern with query parameters.";
} else {
    echo "URL does not match the pattern with query parameters.";
}