RegexExpand

Extract the strings matched to the patterns by doing backslash substitution on the template string. This transformer allow to input multiple regex patterns and multiple match targets, and those can be given in the input value and the argument parameters.

python · Filters And Transformers

Details

IDRegexExpand
Languagepython
From Version6.5.0
Docker Imagedemisto/python3:3.12.13.10404775
Tagstransformer string entirelist

README

Extract the strings matched to the patterns by doing backslash substitution on the template string.
This transformer allow to specify multiple regex patterns and multiple match targets, and those can be given in the input value and the argument parameters.

Script Data


Name Description
Script Type python3
Tags transformer, string, entirelist

Inputs


Argument Name Description
value List of regex or text for the pattern match.
regex A regex pattern to search (in Python).
text A match target text.
template The template text that will be returned for the output by doing backslash substitution to the patterns matched.
template_type The data type of the template.
value_takes Which type of value takes from the value argument, ‘text’ (match target) or ‘regex’.
flags The comma separated flags for pattern matching in regex. “dotall” (s), “multiline” (m), “ignorecase” (i) and “unicode” (u) are supported.
search_limit The maximum limit for scanning patterns. (0 means unlimited)

Outputs


There are no outputs for this script.

import json

import demistomock as demisto


def test_main(mocker):
    from RegexExpand import main

    with open("./test_data/test-1.json") as f:
        test_list = json.load(f)

    for t in test_list:
        mocker.patch.object(
            demisto,
            "args",
            return_value={
                "value": t.get("value"),
                "regex": t.get("regex"),
                "text": t.get("text"),
                "template": t.get("template"),
                "template_type": t.get("template_type"),
                "value_takes": t.get("value_takes"),
                "flags": t.get("flags"),
                "search_limit": t.get("search_limit"),
            },
        )
        mocker.patch.object(demisto, "results")
        main()
        assert demisto.results.call_count == 1
        results = demisto.results.call_args[0][0]

        lhs = results
        rhs = t["result"]
        assert json.dumps(lhs) == json.dumps(rhs)