How can non-capturing groups be utilized in regular expressions to avoid multiple capture groups in PHP?
When using regular expressions in PHP, non-capturing groups can be utilized by using the syntax (?:pattern) to avoid creating multiple capture groups. Non-capturing groups allow you to group patterns together without creating a capture group, which can be useful when you want to match a pattern but do not need to extract that specific part of the string. Example:
$string = "The quick brown fox jumps over the lazy dog";
$pattern = "/(?:brown|black) fox/";
preg_match($pattern, $string, $matches);
echo $matches[0]; // Output: brown fox