# alphanum string filter?

**URL:** <https://forum.ansible.com/t/alphanum-string-filter/23801>\
**Category:** Ansible Project\
**Created:** [February 23, 2017, 12:26am UTC](https://forum.ansible.com/t/alphanum-string-filter/23801 "2017-02-23T00:26:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nusenu1](https://avatars.discourse-cdn.com/v4/letter/n/db5fbb/32.png) [@Nusenu1](https://forum.ansible.com/u/Nusenu1)\
**Post date:** [February 23, 2017, 12:26am UTC](https://forum.ansible.com/t/alphanum-string-filter/23801/1 "2017-02-23T00:26:00Z")

</div>

Hi,

is there a convenient way to filter an arbitrary string for alphanum  
chars only?

example input:  
" 2!bc/ABC\_"

output:  
"2bcABC"

I didn't see something like that on the filter pages:

[http://jinja.pocoo.org/docs/2.9/templates/#builtin-filters](http://jinja.pocoo.org/docs/2.9/templates/#builtin-filters)  
[https://docs.ansible.com/ansible/playbooks\_filters.html](https://docs.ansible.com/ansible/playbooks_filters.html)

thanks,  
nusenu

---

<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:** [February 23, 2017, 12:33am UTC](https://forum.ansible.com/t/alphanum-string-filter/23801/2 "2017-02-23T00:33:17Z")

</div>

Probably with the regex\_replace filter:

foo\>regex\_replace(‘[^a-zA-Z0-9]’, ‘’)

---

<div class="post-metadata">

**Author:** ![Nusenu1](https://avatars.discourse-cdn.com/v4/letter/n/db5fbb/32.png) [@Nusenu1](https://forum.ansible.com/u/Nusenu1)\
**Post date:** [February 23, 2017, 10:51am UTC](https://forum.ansible.com/t/alphanum-string-filter/23801/3 "2017-02-23T10:51:00Z")

</div>

Matt Martz:

> Probably with the regex\_replace filter:
> 
> foo\>regex\_replace('[^a-zA-Z0-9]', '')

thanks!
