$re = '/(?i)\(\s*((?:const\s+)?(?:u?(?:byte|int)\d*|void)(?:\s*\*)?)\s*\)\s*(\w+(?:\((?>[^()]+|(?<c>)\(|(?<-c>)\))*\))?)/m';
$str = '#Pass 1
(void)memcpy(&a[0],(void * )hihi, (UBYTE) V_SIZE);
(void) memcpy((VOID*)abc, (const VOID*) dafa, (uint8)NUMBER_SIZE);
(void )memcpy(
(void *)p,
&abc, (uint8)DATE_SIZE);
#Pass 2
static_cast<void>(memcpy(&a[0],(void * )hihi, (UBYTE) V_SIZE));
static_cast<void>(memcpy((VOID*)abc, (const VOID*) dafa, (uint8)NUMBER_SIZE));
static_cast<void>(memcpy(
(void *)p,
&abc, (uint8)DATE_SIZE));';
$subst = "static_cast<$1>($2)";
$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