Created
August 10, 2017 13:24
-
-
Save kirantambe/b96b21d82a2538833f9a58ebdb955667 to your computer and use it in GitHub Desktop.
Get group(1) for python regex match or None
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
# 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