Skip to content

Instantly share code, notes, and snippets.

@kirantambe
Created August 10, 2017 13:24
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 kirantambe/b96b21d82a2538833f9a58ebdb955667 to your computer and use it in GitHub Desktop.
Save kirantambe/b96b21d82a2538833f9a58ebdb955667 to your computer and use it in GitHub Desktop.
Get group(1) for python regex match or None
# Do a regex search and return group(1) or None
import re
get_match = lambda regex, sample: getattr(re.search(regex, sample), 'group', lambda x: None)(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment