What is the correct syntax for referencing captured subpatterns in regular expressions in PHP?

When using regular expressions in PHP, captured subpatterns can be referenced using backreferences in the form of \1, \2, etc. However, when using double quotes in PHP, backslashes need to be escaped, which can lead to confusion. To correctly reference captured subpatterns in regular expressions in PHP, it is recommended to use single quotes to avoid the need for escaping backslashes.

// Example of referencing captured subpatterns in regular expressions in PHP
$string = "Hello World";
$pattern = '/(Hello) (World)/';
preg_match($pattern, $string, $matches);

// Using single quotes to reference captured subpatterns
echo $matches[0]; // Output: Hello World
echo $matches[1]; // Output: Hello
echo $matches[2]; // Output: World