use strict;
my $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));';
my $regex = qr/(?i)\(\s*((?:const\s+)?(?:u?(?:byte|int)\d*|void)(?:\s*\*)?)\s*\)\s*(\w+(?:\((?>[^()]+|(?<c>)\(|(?<-c>)\))*\))?)/mp;
my $subst = 'static_cast<$1>($2)';
my $result = $str =~ s/$regex/$subst/rg;
print "The result of the substitution is' $result\n";
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 Perl, please visit: http://perldoc.perl.org/perlre.html