How can the PHP function preg_match be used to extract a specific substring from a string based on a pattern?

To extract a specific substring from a string based on a pattern using the PHP function preg_match, you need to provide a regular expression pattern that matches the desired substring. The preg_match function will search the string for the pattern and return the matched substring. This can be useful for extracting specific information, such as email addresses, phone numbers, or other structured data, from a larger string.

$string = "The quick brown fox jumps over the lazy dog";
$pattern = '/quick (.*?) jumps/';
if (preg_match($pattern, $string, $matches)) {
    $specificSubstring = $matches[1];
    echo $specificSubstring; // Output: brown fox
}