What is the correct regex pattern to allow characters like - and _ in a PHP username validation?

When validating usernames in PHP, you may want to allow certain special characters like "-" and "_". To achieve this, you can use a regular expression pattern that includes these characters along with alphanumeric characters. The pattern should start with a letter, followed by letters, numbers, underscores, and hyphens. Here is an example of a regex pattern that allows letters, numbers, hyphens, and underscores in a PHP username validation:

$username = "my_username-123";
if (preg_match('/^[a-zA-Z][a-zA-Z0-9_-]*$/', $username)) {
    echo "Username is valid.";
} else {
    echo "Username is invalid.";
}