What are the advantages of using preg_match in PHP for parsing text inputs compared to other methods?

When parsing text inputs in PHP, using preg_match can be advantageous because it allows for more complex pattern matching using regular expressions. This can make it easier to extract specific information from a string, such as validating email addresses, phone numbers, or other structured data formats. Additionally, preg_match provides more flexibility and control compared to simpler string manipulation functions.

// Example of using preg_match to validate an email address
$email = "example@example.com";

if (preg_match("/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/", $email)) {
    echo "Valid email address";
} else {
    echo "Invalid email address";
}