Created
September 18, 2019 04:03
-
-
Save cherylli/6b44fd5e7f2bb33f0830c10a5f53448e to your computer and use it in GitHub Desktop.
Automate the Boring Stuff with Python Chapter 7 - Regex Version of strip()
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 regex_strip(str, arg=None): | |
if arg is None: | |
return re.sub(r'\s+|\s+$', "", str) | |
else: | |
return re.sub(r'{0}'.format(arg), "", str) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment