How to use regex to filter result before publishing in a Mistral workflow?

howto
mistral

(W Chan) #1

On publish or publish-on-error in Mistral workflow, YAQL or Jinja expressions can be used. There is a regex_match, regex_replace, regex_search, and regex_substring custom functions/filters that StackStorm include. The following is an example in YAQL using regex_match. More examples can be found at st2/contrib/examples/actions/workflows/tests at master · StackStorm/st2 · GitHub.

version: '2.0'

examples.mistral-test-func-regex-match:
    description: A workflow for testing regex_match custom filter in mistral
    type: direct
    input:
        - input_str
        - regex_pattern
    output:
        result_jinja: <% $.result_jinja %>
        result_yaql: <% $.result_yaql %>
    tasks:

        task1:
            action: std.noop
            publish:
                result_jinja: '{{ regex_match(_.input_str, _.regex_pattern) }}'
                result_yaql: '<% regex_match($.input_str, $.regex_pattern) %>'