What are some best practices for handling dollar signs in PHP patterns?

When using dollar signs in PHP patterns, it's important to properly escape them to avoid conflicts with variables. One common approach is to use double backslashes to escape the dollar sign in the pattern string. This ensures that the dollar sign is treated as a literal character in the pattern rather than as a variable indicator.

$pattern = '/\$[0-9]+/';
$subject = 'The price is $20';
preg_match($pattern, $subject, $matches);
print_r($matches);