diff --git a/README.md b/README.md index 323389f..17ee61d 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,8 @@ The files should end in `.txt` and each value should be on it's own line. - `input_text(LIST)`: Choose a line from the files yourself or select `*` to choose at random using seed. - `prefix(STRING)`: The prefix to use - `suffix(STRING)`: The suffix to use -- `regex(STRING)`: If provided this will be used to filter the input files. +- `regex(STRING)`: If provided this will be used to filter the input files. case insensitive. only items that match will be used +- `exclude_regex(STRING)`: If provided this will be used to filter the input files. case insensitive. matched items will not be used - `temp_override(STRING)`: If not blank then overrides the output. - `output_blank_ratio(FLOAT)`: A number between 0 and 1 to determine if the output should be blank. Not used if temp_override is set. diff --git a/wildcard.py b/wildcard.py index 2db7914..494ff3b 100644 --- a/wildcard.py +++ b/wildcard.py @@ -11,6 +11,7 @@ files = list( wildcards_directory.glob("**/*.txt") | map(lambda x: x.relative_to(wildcards_directory)) ) +item_map = dict() def get_items_for_wildcard_path(glob: str): @@ -56,6 +57,10 @@ class SimpleWildcard: "STRING", {"default": ".*"}, ), + "exclude_regex": ( + "STRING", + {"default": ""}, + ), "temp_override": ( "STRING", {"default": ""}, @@ -104,6 +109,9 @@ class SimpleWildcard: if kwargs["regex"] != ".*" or kwargs["regex"] != "": regex = re.compile(kwargs["regex"], re.IGNORECASE) items = list(items | where(regex.match)) + if kwargs["exclude_regex"] != "": + regex = re.compile(kwargs["exclude_regex"], re.IGNORECASE) + items = list(items | where(lambda x: not regex.match(x))) has_items = len(items) > 0 if has_items: