# How to filter string in Ansible using jinja2?

**URL:** <https://forum.ansible.com/t/how-to-filter-string-in-ansible-using-jinja2/29339>\
**Category:** Ansible Project\
**Created:** [December 30, 2018, 3:14am UTC](https://forum.ansible.com/t/how-to-filter-string-in-ansible-using-jinja2/29339 "2018-12-30T03:14:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saravanan](https://avatars.discourse-cdn.com/v4/letter/s/eb8c5e/32.png) [@Saravanan](https://forum.ansible.com/u/Saravanan)\
**Post date:** [December 30, 2018, 3:14am UTC](https://forum.ansible.com/t/how-to-filter-string-in-ansible-using-jinja2/29339/1 "2018-12-30T03:14:55Z")

</div>

Hi Ansible experts,

`  
{  
“outcome” =\> “success”,  
“result” =\> “running”  
}  
{  
“outcome” =\> “success”,  
“result” =\> 2160063879L  
}

`

Please help to filter the string running and the numeric value 2160063879 from the above stdout output using jinja2 filter into two different variables.

---

<div class="post-metadata">

**Author:** ![Piyush\_Bansal](https://avatars.discourse-cdn.com/v4/letter/p/50afbb/32.png) [@Piyush\_Bansal](https://forum.ansible.com/u/Piyush_Bansal)\
**Post date:** [December 31, 2018, 5:54pm UTC](https://forum.ansible.com/t/how-to-filter-string-in-ansible-using-jinja2/29339/2 "2018-12-31T17:54:35Z")

</div>

Hello Saravanan,

Have you tried “Regular Expression Filters” (regex\_search) ??

---

<div class="post-metadata">

**Author:** ![Saravanan](https://avatars.discourse-cdn.com/v4/letter/s/eb8c5e/32.png) [@Saravanan](https://forum.ansible.com/u/Saravanan)\
**Post date:** [January 9, 2019, 12:33pm UTC](https://forum.ansible.com/t/how-to-filter-string-in-ansible-using-jinja2/29339/3 "2019-01-09T12:33:26Z")

</div>

Hi Piyush,  
Using the below Jinja2 filter, able to extract the value 2160063879L. However need to extract exact numeric value alone from sub String by eliminating the letter ‘L’ from the output. Any help much appreciated.

`

```auto
- set_fact:
    upTime: "{{ status.stdout.split()[-2] }}"
  delegate_to: localhost
  become: false
  become_user: awx
  when: status.rc | int == 0
  ignore_errors: yes

```

`

STANDARD OUTPUT  
2160063879L
