# Using special characters in filtered strings

**URL:** <https://forum.ansible.com/t/using-special-characters-in-filtered-strings/19776>\
**Category:** Ansible Project\
**Created:** [November 16, 2015, 8:02pm UTC](https://forum.ansible.com/t/using-special-characters-in-filtered-strings/19776 "2015-11-16T20:02:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tomasz\_Kuchta](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@Tomasz\_Kuchta](https://forum.ansible.com/u/Tomasz_Kuchta)\
**Post date:** [November 16, 2015, 8:02pm UTC](https://forum.ansible.com/t/using-special-characters-in-filtered-strings/19776/1 "2015-11-16T20:02:54Z")

</div>

Hi,

I got stuck with the following:  
Imagine we have a string in stdout of a command that we would like to filter out:

Error123: some ‘thing’ (happened)

If we want to filter that out we would do something like

“{{ item.stderr.regex\_replace(‘Error[0-9]+: some \‘thing\’ \(happened\)’, ‘’) }}”

However due to the fact that we have a colon, a single quote and brackets in our string I was unable to come up with the right escape sequence - whatever I tried, it always failed on one of these.

What would be the right way to escape these special character when they are also used in  
the filter function like regex\_replace?

Thanks!
