Last active
January 12, 2019 01:01
-
-
Save naranjja/8a6e9ccf14d1076d36a793818dbe9a98 to your computer and use it in GitHub Desktop.
Trim padding on string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
def remove_padding(char, s, left=None, right=None): | |
if not left and not right: | |
print("You must specify either left or right.") | |
return | |
elif left: | |
return re.findall(re.escape(char) + r"*(.+)", s)[0] | |
elif right: | |
return re.findall(re.escape(char) + r"*(.+)", s[::-1])[0][::-1] | |
s = "123000000" | |
s_trimmed = remove_padding("0", s, right=True) | |
print(s_trimmed) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment