# Grok match regex

**URL:** <https://discuss.elastic.co/t/grok-match-regex/279957>\
**Category:** Logstash\
**Created:** [July 29, 2021, 9:00am UTC](https://discuss.elastic.co/t/grok-match-regex/279957 "2021-07-29T09:00:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Soren\_vdc](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@Soren\_vdc](https://discuss.elastic.co/u/Soren_vdc)\
**Post date:** [July 29, 2021, 9:00am UTC](https://discuss.elastic.co/t/grok-match-regex/279957/1 "2021-07-29T09:00:18Z")

</div>

Hi,

I want to create grok match and have the 2 first words and the last part of the message.  
For example:  
ERROR;AuthenticationController ;processMessage ;THR=11107194 R=760a52d97983874 T=6031a0711ec3 U=Unauthenticated I=78.21.19.214 A=- C=0001 O=- V=-;Code[TXT-CD,LAA001] transformation to input contract failed

I have this filter  
(?((?:.(?!;))+$))

Result:  
"exceptionHeader": [  
[  
";Code[TXT-CD,LAA001] transformation to input contract failed"  
]  
Any idea how I can add "ERROR;AuthenticationController" to "exceptionHeader"?  
thx

---

<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:** [July 29, 2021, 10:28am UTC](https://discuss.elastic.co/t/grok-match-regex/279957/2 "2021-07-29T10:28:00Z")

</div>

Hi,

I don't know if it's possible to put all the values you want directly in a unique field. So i put values in multiple field and put them together in a new field with add\_field option.  
After that, i remove duplicate data with remove\_field.

```auto
filter {
  grok {
    match => {
      "message" => "^%{DATA:part1};%{DATA:part2};%{GREEDYDATA};%{DATA:part3}$"
    }
    add_field => { "content" => "%{part1};%{part2};%{part3}"}
    remove_field => ["part1", "part2", "part3"]
  }
}

```

Cad.

---

<div class="post-metadata">

**Author:** ![Soren\_vdc](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@Soren\_vdc](https://discuss.elastic.co/u/Soren_vdc)\
**Post date:** [July 29, 2021, 11:11am UTC](https://discuss.elastic.co/t/grok-match-regex/279957/3 "2021-07-29T11:11:18Z")

</div>

> [@Cad](#):
>
> `^%{DATA:part1};%{DATA:part2};%{GREEDYDATA};%{DATA:part3}$`

thanks for the info Cad, it works !

---

<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:** [August 26, 2021, 11:11am UTC](https://discuss.elastic.co/t/grok-match-regex/279957/4 "2021-08-26T11:11:54Z")

</div>

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