# regex\_replace filter

**URL:** <https://forum.ansible.com/t/regex-replace-filter/30075>\
**Category:** Ansible Project\
**Created:** [April 6, 2019, 7:33pm UTC](https://forum.ansible.com/t/regex-replace-filter/30075 "2019-04-06T19:33:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sri\_Krishna\_G](https://avatars.discourse-cdn.com/v4/letter/s/58f4c7/32.png) [@Sri\_Krishna\_G](https://forum.ansible.com/u/Sri_Krishna_G)\
**Post date:** [April 6, 2019, 7:33pm UTC](https://forum.ansible.com/t/regex-replace-filter/30075/1 "2019-04-06T19:33:34Z")

</div>

I have a list of strings like :

`  
[hosts]  
10.100.0.1  
10.100.0.2  
10.100.0.3

`

I am following the example under : [https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_filters.html](https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html) to “add “https://” prefix to each item in a list”  
In my case I am appending the port number at the end of every item in the list and joining them with a “,” to get a string at the end. I am expecting to see something like:

_` 10.100.0.1:2181,10.100.0.2:2181,10.100.0.3:2181 `_ I am creating a variable as:

`

zookeeper\_masters: “{{‘zk://’ + hosts | map(‘regex\_replace’, ‘^(.\*)$’, ‘\1:2181’) | join(‘,’)}}”

`

My result comes as:

`

“zk://10.100.0.1:2181:2181,10.100.0.2:2181:2181,10.100.0.3:2181:2181”

`

Can some one point out as to why I am getting the port number twice?

---

<div class="post-metadata">

**Author:** ![Sri\_Krishna\_G](https://avatars.discourse-cdn.com/v4/letter/s/58f4c7/32.png) [@Sri\_Krishna\_G](https://forum.ansible.com/u/Sri_Krishna_G)\
**Post date:** [April 7, 2019, 5:13am UTC](https://forum.ansible.com/t/regex-replace-filter/30075/2 "2019-04-07T05:13:32Z")

</div>

Please ignore this issue. It was a mistake in the next part of the play book that is causing the port to come twice.
