# How to replace all groups of number in a string using gsub

**URL:** <https://discuss.elastic.co/t/how-to-replace-all-groups-of-number-in-a-string-using-gsub/288761>\
**Category:** Logstash\
**Created:** [November 9, 2021, 1:32pm UTC](https://discuss.elastic.co/t/how-to-replace-all-groups-of-number-in-a-string-using-gsub/288761 "2021-11-09T13:32:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gustavon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gustavon/32/96907_2.png) [@gustavon](https://discuss.elastic.co/u/gustavon)\
**Post date:** [November 9, 2021, 1:32pm UTC](https://discuss.elastic.co/t/how-to-replace-all-groups-of-number-in-a-string-using-gsub/288761/1 "2021-11-09T13:32:53Z")

</div>

Hi,

I have an uri on nginx log like this: /xyz/attachment/thumbnail/61355754/90/90 and others, so I need to use gsub to replace all number to something else, /xyz/attachment/thumbnail/{}/{}/{} for example, I tried to use this configuration:

# Remove number from uri and create a new field clean\_uri

```auto
  if [i_uri] {
    mutate {
      add_field => { "clean_uri" => "%{[i_uri]}"}
    }
    mutate {
      gsub => ["[clean_uri]", "/\b\d+\b/", "/{}/"]
    }
  }

```

But the regex "/\b\d+\b/" is not replacing all, this replaces only the first group of numbers like this: /xyz/attachment/thumbnail/{}/90/90, how do I replace all, like a global regex.

---

<div class="post-metadata">

**Author:** ![gustavon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gustavon/32/96907_2.png) [@gustavon](https://discuss.elastic.co/u/gustavon)\
**Post date:** [November 9, 2021, 5:49pm UTC](https://discuss.elastic.co/t/how-to-replace-all-groups-of-number-in-a-string-using-gsub/288761/2 "2021-11-09T17:49:00Z")

</div>

The issue was solved using:

```auto
# Remove number from uri and create a new field clean-uri
          if [i_uri] {
            mutate {
              add_field => { "clean-uri" => "%{i_uri}"}
            }
            mutate {
              gsub => ["[clean-uri]", "(\b\d+\b)", "*"]
            }
          }

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 7, 2021, 5:49pm UTC](https://discuss.elastic.co/t/how-to-replace-all-groups-of-number-in-a-string-using-gsub/288761/3 "2021-12-07T17:49:28Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
