# Ruby or groak for string menuplation

**URL:** <https://discuss.elastic.co/t/ruby-or-groak-for-string-menuplation/217236>\
**Category:** Logstash\
**Created:** [January 30, 2020, 3:57pm UTC](https://discuss.elastic.co/t/ruby-or-groak-for-string-menuplation/217236 "2020-01-30T15:57:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)\
**Post date:** [January 30, 2020, 3:57pm UTC](https://discuss.elastic.co/t/ruby-or-groak-for-string-menuplation/217236/1 "2020-01-30T15:57:30Z")

</div>

I have a two different type of string

example1\_string = /a/b/c/./d/e ( if found . then I just want to remove only './' )  
example2\_sting = /a/b/c/../d/e ( if found .. anywhere in string then I want to just remove ' c/../' )

and if no . or no .. then leave it as is.

How do I achieve this?

and this string might be more or less in length, not exactly upto e.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [January 30, 2020, 4:03pm UTC](https://discuss.elastic.co/t/ruby-or-groak-for-string-menuplation/217236/2 "2020-01-30T16:03:46Z")

</div>

Use mutate+gsub

```
 mutate { gsub => ["message", "/\./", "/", "message", "/[^.]/\.\./", "/" ] }
```

---

<div class="post-metadata">

**Author:** ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)\
**Post date:** [January 30, 2020, 4:21pm UTC](https://discuss.elastic.co/t/ruby-or-groak-for-string-menuplation/217236/3 "2020-01-30T16:21:07Z")

</div>

> [@Badger](#):
>
> mutate { gsub =\> ["message", "/./", "/", "message", "/[^.]/../", "/" ] }

Thank you for fast reply Badger

. was removed. but .. didn't

here is example again  
/a/b/change/../d/e -\> /ab/d/e (this is result I am looking for)

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [January 30, 2020, 4:38pm UTC](https://discuss.elastic.co/t/ruby-or-groak-for-string-menuplation/217236/4 "2020-01-30T16:38:27Z")

</div>

> [@elasticforme](#):
>
> "/[^.]/../"

If you need to match more than a single character then try

```
"/[^./]+/../"

```

---

<div class="post-metadata">

**Author:** ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)\
**Post date:** [January 30, 2020, 4:49pm UTC](https://discuss.elastic.co/t/ruby-or-groak-for-string-menuplation/217236/5 "2020-01-30T16:49:44Z")

</div>

@Badger you are star. done. working

---

<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:** [February 27, 2020, 4:49pm UTC](https://discuss.elastic.co/t/ruby-or-groak-for-string-menuplation/217236/6 "2020-02-27T16:49:48Z")

</div>

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