ReplaceMatchGroup
Returns a string with all matches of a regex pattern groups replaced by a replacement.
- Type
- python
- Pack
- CommonScripts
Source
import re
import demistomock as demisto
from CommonServerPython import *
def main(args):
value = args["value"]
replace_with = args["replace_with"]
output = []
start = 0
try:
regex = re.compile(args["regex"])
except (re.error, TypeError):
raise DemistoException("Could not compile regex.")
for match in regex.finditer(value):
for index, _ in enumerate(match.groups(), start=1):
end = match.start(index)
output.append(value[start:end])
output.append(replace_with)
start = match.end(index)
output.append(value[start:]) # Handling the tail of the string
return "".join(output)
if __name__ in ["__builtin__", "builtins", "__main__"]:
result = main(demisto.args())
demisto.results(result)
README
Returns a string with all matches of a regex pattern groups replaced by a replacement.
Script Data
| Name | Description |
|---|---|
| Script Type | python3 |
| Tags | transformer |
| Cortex XSOAR Version | 5.0.0 |
Inputs
| Argument Name | Description |
|---|---|
| value | An array of email addresses to be filtered by domain. |
| regex | A regex pattern who’s groups to be replaced by the replaceWith argument. |
| replace_with | The replacement string. |
Outputs
There are no outputs for this script.