$re = '/(?:"raw":\s*")(?:.*?)([0-9]{4})(?:[^"]*")/m';
$str = '{ "comment": "This regex is designed to turn raw fields in CSL-JSON into year only, leaving literal CE BC?E dates alone"
{"raw": "2006"}
{
"raw": "2006 Feb"
}
{"raw": "Feb 2021"}
{"raw":"2006 Mar 12"}
{"raw":"2006-12-12"}
{"raw":"2006 02 04"}
{ "raw": "2006-12-12" }
{"raw": "350 B.C.E."}
';
$subst = "\"raw\": \"$1\"";
$result = preg_replace($re, $subst, $str);
echo "The result of the substitution is ".$result;
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php