How can the regex101 tool be helpful in testing and refining regex patterns for use in PHP?

Regex101 tool can be helpful in testing and refining regex patterns for use in PHP by allowing users to input their regex pattern and test it against sample text. This tool provides a detailed breakdown of the regex pattern, highlighting matches and explaining any errors. By using this tool, developers can quickly iterate on their regex patterns, fine-tune them, and ensure they work as intended before implementing them in their PHP code.

$regex_pattern = '/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/i';
$text = "john.doe@example.com";

if (preg_match($regex_pattern, $text)) {
    echo "Valid email address";
} else {
    echo "Invalid email address";
}