Skip to content

Instantly share code, notes, and snippets.

@saintsGrad15
Created January 21, 2021 16:45
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 saintsGrad15/5012d20702ee4aa7d774fd842fdff715 to your computer and use it in GitHub Desktop.
Save saintsGrad15/5012d20702ee4aa7d774fd842fdff715 to your computer and use it in GitHub Desktop.
A regex that validates and extracts groups from a valid HTTP "range" header
# Spec source: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range
import re
range_header_regex = re.compile(r"^((?P<unit>[a-zA-Z]+)=)?(?P<start>\d+)?-(?P<end>\d+)?$")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment