# matching a string with search pattern having dots

**URL:** <https://forum.ansible.com/t/matching-a-string-with-search-pattern-having-dots/17833>\
**Category:** Ansible Project\
**Created:** [March 25, 2015, 10:01am UTC](https://forum.ansible.com/t/matching-a-string-with-search-pattern-having-dots/17833 "2015-03-25T10:01:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Max1](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Max1](https://forum.ansible.com/u/Max1)\
**Post date:** [March 25, 2015, 10:01am UTC](https://forum.ansible.com/t/matching-a-string-with-search-pattern-having-dots/17833/1 "2015-03-25T10:01:17Z")

</div>

Hello

Here are the two scenarios:

1. This one works:  
when: ansible\_hostname | search(“test1-1-xx-1”)

2)This one is not able to match the string probably because of dots  
when: ansible\_hostname | search(“[test1-1-xx-1.tom.com](http://test1-1-xx-1.tom.com)”)

I even tried escapting dots with a backslash without any success.

Any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [March 25, 2015, 4:20pm UTC](https://forum.ansible.com/t/matching-a-string-with-search-pattern-having-dots/17833/2 "2015-03-25T16:20:33Z")

</div>

I imagine the problem is that ansible\_hostname is the portion of the fqdn. hostname before the first dot. You will likely want to look at ansible\_fqdn instead.

If you run the setup module against a host, you should be able to look at all of the facts to find the appropriate fact names.

---

<div class="post-metadata">

**Author:** ![Max1](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Max1](https://forum.ansible.com/u/Max1)\
**Post date:** [March 31, 2015, 12:53pm UTC](https://forum.ansible.com/t/matching-a-string-with-search-pattern-having-dots/17833/3 "2015-03-31T12:53:41Z")

</div>

Thanks for the info Matt. I Don’t have DNS configured and hence even ‘ansible\_fqdn’ is giving me random stuff. For time being I’ve fixed it with ‘group[‘groupname’]’ to iterate over my group and do some regex matching.
