# Regex pattern for selecting an inverted word on a list of strings

**URL:** <https://forum.ansible.com/t/regex-pattern-for-selecting-an-inverted-word-on-a-list-of-strings/30964>\
**Category:** Ansible Project\
**Created:** [August 6, 2019, 12:57pm UTC](https://forum.ansible.com/t/regex-pattern-for-selecting-an-inverted-word-on-a-list-of-strings/30964 "2019-08-06T12:57:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![actionmystique](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/actionmystique/32/1678_2.png) [@actionmystique](https://forum.ansible.com/u/actionmystique)\
**Post date:** [August 6, 2019, 12:57pm UTC](https://forum.ansible.com/t/regex-pattern-for-selecting-an-inverted-word-on-a-list-of-strings/30964/1 "2019-08-06T12:57:18Z")

</div>

The goal is to **select all the lines of a list which do NOT contain a specific word**.

For instance, “{{ files }}” contains a list of filenames. We need to select all the filenames which do not include the word ‘all’.

So with:

files:

- aaaaaaaaaaa
- bbbbbbbbbbb
- cccccccccccc
- d-all-ddddddd

The expected result would be:

files\_filtered::

- aaaaaaaaaaa
- bbbbbbbbbbb
- cccccccccccc

I unsuccessfully tried:

set\_fact:  
files\_filtered: “{{ files | select(‘match’, ‘^(._^((?!all).)_.+)$’) | list }}”

The result is empty.

Any suggestion?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 6, 2019, 1:12pm UTC](https://forum.ansible.com/t/regex-pattern-for-selecting-an-inverted-word-on-a-list-of-strings/30964/2 "2019-08-06T13:12:58Z")

</div>

Use reject instead of select, and since you looking for containing use search instead of match.

&nbsp;&nbsp;&nbsp;{{ files | reject('search', 'all') | list }}
