Notes

Some Regex Notes

I happened to be dealing with a bunch of mallocs that look like this

double* f =  (double*)malloc(sizeof(double)*nx*ny*nz);
double* g = (double*)malloc(sizeof(double)*nx);
double* h = (double*)malloc(sizeof(double)*nx*nz);

I wanted to convert all of those those to use new, i.e.

double* f = new double[nx*ny*nz]

Using regex made all this possible

search for: \(double\*\)malloc\(sizeof\(double\)\*(.*)\)
replace with: new double[$1]

 

Leave a Reply