If you don't mind writing the algo (or using one of the library ones), for global replace, grab the entire edit content into memory, global replace on the memory then write the results back to the editor. If you can stay at the same or similar line number after, its easier to use.