Skip to content

Instantly share code, notes, and snippets.

@cherylli
Created September 18, 2019 04:03
Show Gist options
  • Save cherylli/6b44fd5e7f2bb33f0830c10a5f53448e to your computer and use it in GitHub Desktop.
Save cherylli/6b44fd5e7f2bb33f0830c10a5f53448e to your computer and use it in GitHub Desktop.
Automate the Boring Stuff with Python Chapter 7 - Regex Version of strip()
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