How can escaping characters in PHP regular expressions prevent errors like "Unknown modifier"?

When using regular expressions in PHP, certain characters like slashes (/) can be misinterpreted as delimiters, causing errors like "Unknown modifier". To prevent this, you can escape these characters using a backslash (\) before them in the regular expression pattern. This tells PHP to interpret the character as a literal character rather than a delimiter. Example PHP code snippet:

$pattern = '/^https:\/\/www\.example\.com$/';
$string = 'https://www.example.com';

if (preg_match($pattern, $string)) {
    echo 'Match found!';
} else {
    echo 'No match found.';
}