How can one avoid errors related to unmatched parentheses when using preg_match_all in PHP?

When using preg_match_all in PHP, unmatched parentheses can occur if the regular expression pattern contains parentheses that are not properly closed or opened. To avoid this error, it is important to ensure that all opening parentheses have a corresponding closing parentheses in the regular expression pattern.

// Example of avoiding unmatched parentheses with preg_match_all
$pattern = '/(example)/'; // Correctly matched parentheses
$string = 'This is an example of using preg_match_all in PHP';
preg_match_all($pattern, $string, $matches);
print_r($matches);