# Extracting parts of a string

**URL:** <https://forum.ansible.com/t/extracting-parts-of-a-string/4941>\
**Category:** Get Help\
**Created:** [April 14, 2024, 12:23pm UTC](https://forum.ansible.com/t/extracting-parts-of-a-string/4941 "2024-04-14T12:23:56Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [April 14, 2024, 1:30pm UTC](https://forum.ansible.com/t/extracting-parts-of-a-string/4941/2 "2024-04-14T13:30:34Z")

</div>

> [@dulhaver](#):
>
> how do I extract `nexus-3.67.1-01` from `/opt/nexus/install/nexus-3.67.1-01-unix.tar.gz` in order to use that in a new path?

I posted an answer for that in [the last thread](http://forum.ansible.com/t/unarchive-using-wildcards-in-src-option/4876/4), you can use the basename filter to get just the filename and [regex\_replace filter](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/regex_replace_filter.html) to remove the start and the ends of the filename, for example, something like this:

```yaml
- name: Set a fact for the Nexus version
  ansible.builtin.set_fact:
    nexus_version: >-
      {{ nexus_path |
      ansible.builtin.basename |
      ansible.builtin.regex_replace('^nexus-') |
      ansible.builtin.regex_replace('-unix[.]tar[.]gz$') }}
  vars:
    nexus_path: /opt/nexus/install/nexus-3.67.1-01-unix.tar.gz

```

---

_[View the full topic](https://forum.ansible.com/t/extracting-parts-of-a-string/4941)._
