How can one effectively test and debug regular expressions in PHP?

To effectively test and debug regular expressions in PHP, one can use online tools like regex101.com to input the regular expression and test it against sample data. Additionally, using PHP functions like preg_match() or preg_match_all() can help validate the regular expression against actual data in your PHP code. Finally, using var_dump() or print_r() to output the results of the regular expression match can help debug any issues.

$regex = "/^[a-zA-Z0-9]+$/";
$string = "Test123";

if (preg_match($regex, $string)) {
    echo "Regular expression matches!";
} else {
    echo "Regular expression does not match!";
}