Search code examples
jinja2dbt

how to use python regex functions in dbt-jinja?


this PR adds all the re module functions to dbt-jinja, but how to use it? I tried the below two, but to no avail.

{% set matcher = re.match('Doug', 'Timestamps Doug') %}
're' is undefined. This can happen when calling a macro that does not exist. Check for typos and/or install package dependencies with "dbt deps".
{% set matcher = match('Doug', 'Timestamps Doug') %}
> 'match' is undefined. This can happen when calling a macro that does not exist. Check for typos and/or install package dependencies with "dbt deps".

Solution

  • as was pointed out in a comment in the PR, there is a doc page that details that to use the re module, you prefix it's usage with modules.

    {% set matcher = modules.re.match('Doug', 'Timestamps Doug') %}