# Grok ignore possible extra word/text at end of the line?

**URL:** <https://discuss.elastic.co/t/grok-ignore-possible-extra-word-text-at-end-of-the-line/304026>\
**Category:** Logstash\
**Created:** [May 5, 2022, 11:54am UTC](https://discuss.elastic.co/t/grok-ignore-possible-extra-word-text-at-end-of-the-line/304026 "2022-05-05T11:54:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tjswe](https://avatars.discourse-cdn.com/v4/letter/t/8e7dd6/32.png) [@tjswe](https://discuss.elastic.co/u/tjswe)\
**Post date:** [May 5, 2022, 11:54am UTC](https://discuss.elastic.co/t/grok-ignore-possible-extra-word-text-at-end-of-the-line/304026/1 "2022-05-05T11:54:40Z")

</div>

Slightly embarrassed, but i can not find the answer of a what feels like simple question.

Data looks like this  
ABC WORD1 DEF WORD2 GHI WORD3  
or  
ABC WORD1 DEF WORD2 GHI WORD3 (nonimportanttext)

This below works with Example 1 (missing the non-important text in parentheses)  
ABC %{DATA:first} DEF %{DATA:second} GHI %{DATA:third}$

But how do i ignore the non important text in the second line? Is it possible with a OR-statement?

---

<div class="post-metadata">

**Author:** ![Cad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cad/32/86661_2.png) [@Cad](https://discuss.elastic.co/u/Cad)\
**Post date:** [May 5, 2022, 12:38pm UTC](https://discuss.elastic.co/t/grok-ignore-possible-extra-word-text-at-end-of-the-line/304026/2 "2022-05-05T12:38:48Z")

</div>

Hi,

You can make optionnal pattern using `(%{pattern})?`

So in your case a pattern like this will work :  
`ABC %{DATA:first} DEF %{DATA:second} GHI %{DATA:third}( .*)?$`

`( .*)?` means that it is possible to have a space followed by [0 - ∞] charactere(s)

Cad.

---

<div class="post-metadata">

**Author:** ![tjswe](https://avatars.discourse-cdn.com/v4/letter/t/8e7dd6/32.png) [@tjswe](https://discuss.elastic.co/u/tjswe)\
**Post date:** [May 5, 2022, 1:13pm UTC](https://discuss.elastic.co/t/grok-ignore-possible-extra-word-text-at-end-of-the-line/304026/3 "2022-05-05T13:13:48Z")

</div>

> [@Cad](#):
>
> ( .\*)?$

Of course!

Thanks!

---

<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:** [May 5, 2022, 4:03pm UTC](https://discuss.elastic.co/t/grok-ignore-possible-extra-word-text-at-end-of-the-line/304026/4 "2022-05-05T16:03:48Z")

</div>

> [@tjswe](#):
>
> But how do i ignore the non important text in the second line?

Another approach could be using

```
ABC %{DATA:first} DEF %{DATA:second} GHI %{NOTSPACE:third}

```

to match both.

---

<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:** [June 2, 2022, 4:04pm UTC](https://discuss.elastic.co/t/grok-ignore-possible-extra-word-text-at-end-of-the-line/304026/5 "2022-06-02T16:04:35Z")

</div>

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