Are there best practices for using regular expressions in PHP to enhance code readability and maintainability?

Regular expressions can be powerful tools in PHP, but they can also make code difficult to read and maintain if not used properly. To enhance readability and maintainability, it's important to use descriptive variable names, comment complex patterns, and break down long patterns into smaller, more manageable parts. Additionally, consider using the `x` modifier to allow for whitespace and comments within the pattern, making it easier to understand.

// Example of using regular expressions with enhanced readability and maintainability

$pattern = '/
    ^           # Start of string
    [a-zA-Z]    # Match a single letter
    \d{3}       # Match exactly 3 digits
    -           # Match a hyphen
    [a-z]{2}    # Match exactly 2 lowercase letters
    $           # End of string
/x';

if (preg_match($pattern, $input)) {
    echo "Pattern matched!";
} else {
    echo "Pattern not matched.";
}