How can non-capturing subpatterns improve the readability and efficiency of regular expressions in PHP?

Non-capturing subpatterns can improve the readability and efficiency of regular expressions in PHP by allowing you to group parts of the pattern without capturing them as separate matches. This can make the regular expression easier to understand as it clearly defines the structure of the pattern without cluttering the match results with unnecessary captures. Additionally, non-capturing subpatterns can improve performance by reducing the overhead of capturing and storing unnecessary match results.

// Example of using non-capturing subpatterns in PHP
$pattern = '/(?:https?:\/\/)?(?:www\.)?example\.com/';
$string = 'Visit https://www.example.com for more information';

if (preg_match($pattern, $string, $matches)) {
    echo 'Match found: ' . $matches[0];
} else {
    echo 'No match found';
}