What are the limitations of using manual string manipulation methods, like substr() and strpos(), for complex string operations in PHP?

Using manual string manipulation methods like substr() and strpos() can be cumbersome and error-prone when dealing with complex string operations in PHP. To simplify and improve the readability of the code, it is recommended to use regular expressions (regex) which provide more powerful and flexible ways to manipulate strings.

// Example of using regular expressions to extract a specific pattern from a string
$string = "Hello, my email is john.doe@example.com";
$pattern = '/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/';
preg_match($pattern, $string, $matches);
$email = $matches[0];
echo $email; // Output: john.doe@example.com