# GROK Custom Pattern help. Drop leading and trailing spaces

**URL:** <https://discuss.elastic.co/t/grok-custom-pattern-help-drop-leading-and-trailing-spaces/261037>\
**Category:** Logstash\
**Created:** [January 13, 2021, 6:46pm UTC](https://discuss.elastic.co/t/grok-custom-pattern-help-drop-leading-and-trailing-spaces/261037 "2021-01-13T18:46:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fastxl](https://avatars.discourse-cdn.com/v4/letter/f/85e7bf/32.png) [@fastxl](https://discuss.elastic.co/u/fastxl)\
**Post date:** [January 13, 2021, 6:46pm UTC](https://discuss.elastic.co/t/grok-custom-pattern-help-drop-leading-and-trailing-spaces/261037/1 "2021-01-13T18:46:31Z")

</div>

Looking to GROK the following data  
`"(DATA: SOME STUFF)"`  
What I am after is "SOME STUFF". When I use the following  
`\(DATA: (?<DATA> *(.+?) *)\)`  
I get this result in the debugger  
`{ "DATA": "SOME STUFF" }`  
but if my data looks like this `"(DATA: SOME STUFF )"`  
I get this result `{ "DATA": "SOME STUFF " }` with trailing spaces. Basically I DO NOT want the leading or trailing spaces around `SOME STUFF`. How can I drop these?

---

<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 13, 2021, 8:41pm UTC](https://discuss.elastic.co/t/grok-custom-pattern-help-drop-leading-and-trailing-spaces/261037/2 "2021-01-13T20:41:36Z")

</div>

Use mutate+gsub to remove them.

```
mutate { gsub => ["DATA", "^\s+", "", "DATA", "\s+$", ""] }
```

---

<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 10, 2021, 8:41pm UTC](https://discuss.elastic.co/t/grok-custom-pattern-help-drop-leading-and-trailing-spaces/261037/3 "2021-02-10T20:41:52Z")

</div>

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