Skip to content

Instantly share code, notes, and snippets.

@LeviTaule
Created July 18, 2016 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeviTaule/979df6036ddc601fde6d9893f9c3db8d to your computer and use it in GitHub Desktop.
Save LeviTaule/979df6036ddc601fde6d9893f9c3db8d to your computer and use it in GitHub Desktop.
rreplace()
# rreplace() for Python - replace string from right side
# Copyright (c) 2016 Levi Taule
#
# This software is provided 'as-is', without any express or implied
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not
# claim that you wrote the original software. If you use this software
# in a product, an acknowledgement in the product documentation would be
# appreciated but is not required.
# 2. Altered source versions must be plainly marked as such, and must not be
# misrepresented as being the original software.
# 3. This notice may not be removed or altered from any source distribution.
def rreplace(source, old, new, count = -1):
return source[::-1].replace(old[::-1], new[::-1], count)[::-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment