# Nested variables and Regex...

**URL:** <https://forum.ansible.com/t/nested-variables-and-regex/24920>\
**Category:** Ansible Project\
**Created:** [July 7, 2017, 10:01am UTC](https://forum.ansible.com/t/nested-variables-and-regex/24920 "2017-07-07T10:01:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rene](https://avatars.discourse-cdn.com/v4/letter/r/7cd45c/32.png) [@rene](https://forum.ansible.com/u/rene)\
**Post date:** [July 7, 2017, 10:01am UTC](https://forum.ansible.com/t/nested-variables-and-regex/24920/1 "2017-07-07T10:01:12Z")

</div>

Dear community,

sorry that I have to bother you but I don’t get it.

My goal is to create a nested variables which consists of a static text and two other variables. The thing is, the two variables may contain characters that should be “removed”.

This is my (java) regex: [\s,.;-\_]+

And I wanted to do something like that:

`elasticsearchclustername: "es{{ server_hostname | regex_replace('([\\s\\,\\.\\;\\-\\_]+)') }}{{ software_version | regex_replace('([\\s\\,\\.\\;\\-\\_]+)') }}"`

After that I use the new variable (elasticsearchclustername) within different jinja2 templates. But that is when I get an “recursive loop detected in template” error.

I really hate regex and I would appreciate any input.

Thanks in advance.

René

---

<div class="post-metadata">

**Author:** ![Daniel\_JD](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@Daniel\_JD](https://forum.ansible.com/u/Daniel_JD)\
**Post date:** [July 7, 2017, 7:10pm UTC](https://forum.ansible.com/t/nested-variables-and-regex/24920/2 "2017-07-07T19:10:19Z")

</div>

Here you go:

# elasticsearchclustername: “es{{ (server\_hostname + software\_version) | regex\_replace(‘[.,;-]+’, ‘’) }}”

---

<div class="post-metadata">

**Author:** ![rene](https://avatars.discourse-cdn.com/v4/letter/r/7cd45c/32.png) [@rene](https://forum.ansible.com/u/rene)\
**Post date:** [July 10, 2017, 9:03am UTC](https://forum.ansible.com/t/nested-variables-and-regex/24920/3 "2017-07-10T09:03:40Z")

</div>

Thanks for helping me out. 🙂

Sadly it looks like that the construct itself is the issue and not the regex. After I resolved the “recursive loop detected in template” issue, I ran into another one. I have to dig into that one first to resolve this entirely.

Nevertheless thanks for your help. 🙂
