How can regular expressions be utilized to reformat dates in PHP?

Regular expressions can be utilized in PHP to reformat dates by matching the date pattern in the original format and then using the preg_replace function to replace it with the desired format. For example, if the original date format is "dd-mm-yyyy" and we want to reformat it to "yyyy-mm-dd", we can use a regular expression to match the pattern of the original date and then replace it with the desired format.

$originalDate = "25-12-2022";
$reformattedDate = preg_replace('/(\d{2})-(\d{2})-(\d{4})/', '$3-$2-$1', $originalDate);

echo $reformattedDate; // Output: 2022-12-25