Skip to content

Instantly share code, notes, and snippets.

@jonmorehouse
Created October 25, 2019 19:15
Show Gist options
  • Save jonmorehouse/2c773e66ba37fc3b324e940a0ad707b2 to your computer and use it in GitHub Desktop.
Save jonmorehouse/2c773e66ba37fc3b324e940a0ad707b2 to your computer and use it in GitHub Desktop.
uri = '/httpbin/headers'
# we want to strip the `/httpbin` off the front
new_uri = uri.lstrip('/httpbin')
# this returns 'eaders' because it treats the input into lstrip as a set of characters to strip. So it strips all of
# those characters until it finds something that is not in one of those (e)
# now, let's try with something more predictable
uri = '/httpbin/status'
# this returns status, as expected!
new_uri = uri.lstrip('/httpbin')
# to properly split this, we need to use regex:
uri = '/httpbin/headers'
new_uri = re.sub(r'^/httpbin', '', uri)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment