Created
February 1, 2021 17:18
-
-
Save mcm/91a610ca0461eefac94ce8d904312415 to your computer and use it in GitHub Desktop.
This file contains 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
def extract_regex(input_text=None, regex=None, **kwargs): | |
""" | |
Args: | |
input_text | |
regex | |
Returns a JSON-serializable object that implements the configured data paths: | |
groups | |
groupdict.* | |
""" | |
############################ Custom Code Goes Below This Line ################################# | |
import json | |
import re | |
import phantom.rules as phantom | |
outputs = { | |
"groups": [], | |
"groupdict": {} | |
} | |
regex = re.compile(regex) | |
m = regex.search(input_text) | |
if m: | |
outputs["groups"] = m.groups() | |
outputs["groupdict"] = m.groupdict() | |
# Return a JSON-serializable object | |
assert json.dumps(outputs) # Will raise an exception if the :outputs: object is not JSON-serializable | |
return outputs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment