How can the greediness of quantifiers be controlled in PHP regular expressions?

The greediness of quantifiers in PHP regular expressions can be controlled by using the "?" modifier after the quantifier. This modifier makes the quantifier non-greedy, meaning it will match as few characters as possible. This is useful when you want to match the smallest possible substring that satisfies the pattern. Example: To make a quantifier non-greedy in PHP regular expressions, you can use the "?" modifier. For example, if you want to match the smallest possible substring between "a" and "b" in the string "ababab", you can use the pattern "/a.*?b/". This will match "ab" instead of the entire string.

$string = "ababab";
$pattern = "/a.*?b/";
preg_match($pattern, $string, $matches);
echo $matches[0]; // Output: ab