Add limit parameter to replace()

The implementation of that is somewhat ugly :)