What are the best practices for anchoring regular expressions to capture content before and within parentheses in PHP?

When capturing content before and within parentheses using regular expressions in PHP, it is important to anchor the expression to ensure accurate matching. One way to do this is by using the "^" symbol to anchor the expression at the beginning of the string, and "$" to anchor it at the end. Additionally, using non-greedy quantifiers like "?" can help capture content within parentheses without including extra characters.

$string = "This is a (sample) text with (multiple) parentheses";
preg_match_all('/\((.*?)\)/', $string, $matches);

print_r($matches[1]);