How can regular expressions (regex) be effectively used in PHP to validate complex input patterns like ISBN numbers?

Regular expressions can be effectively used in PHP to validate complex input patterns like ISBN numbers by creating a regex pattern that matches the specific format of an ISBN. This pattern can then be used with PHP's preg_match function to check if the input string conforms to the ISBN format.

$isbn = "978-3-16-148410-0";
$pattern = "/^(97(8|9))?\d{9}(\d|X)$/";

if (preg_match($pattern, $isbn)) {
    echo "Valid ISBN number";
} else {
    echo "Invalid ISBN number";
}