Create robustlinereplace

See inline comments for more documentation.