semgrep will at least do the search portion, not sure about replace. Posted a few days ago:
https://news.ycombinator.com/item?id=23919313
Slightly related:
How to Build Static Checking Systems Using Orders of Magnitude Less Code
https://web.stanford.edu/~mlfbrown/paper.pdf
They use "microgrammars" and found that the technique is surprisingly effective despite not being "correct".