# Grok regex pattern for symbols?

**URL:** <https://discuss.elastic.co/t/grok-regex-pattern-for-symbols/286624>\
**Category:** Logstash\
**Created:** [October 13, 2021, 1:10pm UTC](https://discuss.elastic.co/t/grok-regex-pattern-for-symbols/286624 "2021-10-13T13:10:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![helloworld1234](https://avatars.discourse-cdn.com/v4/letter/h/7feea3/32.png) [@helloworld1234](https://discuss.elastic.co/u/helloworld1234)\
**Post date:** [October 13, 2021, 1:10pm UTC](https://discuss.elastic.co/t/grok-regex-pattern-for-symbols/286624/1 "2021-10-13T13:10:59Z")

</div>

Lets say I have a string:

```auto
"petBreed":"dachshund" "petName":"rufus" "petAge":"12"

```

The value is not constant and can vary in length and content.

And i want to use grok overwrite to remove rufus from the raw string.

So a lookbehind and lookahead regex pattern that matches based on a match to petName, then removes the string after it thru grok overwrite

---

<div class="post-metadata">

**Author:** ![AquaX](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aquax/32/92006_2.png) [@AquaX](https://discuss.elastic.co/u/AquaX)\
**Post date:** [October 13, 2021, 3:27pm UTC](https://discuss.elastic.co/t/grok-regex-pattern-for-symbols/286624/2 "2021-10-13T15:27:16Z")

</div>

> [@helloworld1234](#):
>
> `"petBreed":"dachshund" "petName":"rufus" "petAge":"12"`

When using a grok pattern you have to match the whole string in some way shape or form. However, if you don't care about the value of petName then don't assign a field name to that pattern.

`"petBreed":"%{NOTSPACE:petBreedFieldValue}" "petName":"%{NOTSPACE}" "petAge":%{NOTSPACE:petAgeFieldValue}`

```auto
{
  "petBreedFieldValue": [
    [
      "dachshund"
    ]
  ],
  "NOTSPACE": [
    [
      "rufus"
    ]
  ],
  "petAgeFieldValue": [
    [
      ""12""
    ]
  ]
}

```

You could also skip that field entirely:

```auto
"petBreed":"%{NOTSPACE:petBreedFieldValue}" %{DATA} "petAge":"%{NOTSPACE:petAgeFieldValue}"

```

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [October 13, 2021, 3:44pm UTC](https://discuss.elastic.co/t/grok-regex-pattern-for-symbols/286624/3 "2021-10-13T15:44:59Z")

</div>

If your message/string has this format:

```auto
"petBreed":"dachshund" "petName":"rufus" "petAge":"12"

```

You do not need grok to parse it, you can use the `kv` filter.

---

<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:** [October 13, 2021, 4:12pm UTC](https://discuss.elastic.co/t/grok-regex-pattern-for-symbols/286624/4 "2021-10-13T16:12:42Z")

</div>

> [@AquaX](#):
>
> When using a grok pattern you have to match the whole string in some way shape or form.

No, you do not. grok is quite happy to match a pattern in the middle of a string. If [message] contains

```
"petBreed":"dachshund" "petName":"rufus" "petAge":"12"

```

then

```
grok { match => { "message" => 'Name":"%{WORD:name' }

```

will work just fine.

---

<div class="post-metadata">

**Author:** ![helloworld1234](https://avatars.discourse-cdn.com/v4/letter/h/7feea3/32.png) [@helloworld1234](https://discuss.elastic.co/u/helloworld1234)\
**Post date:** [October 13, 2021, 4:13pm UTC](https://discuss.elastic.co/t/grok-regex-pattern-for-symbols/286624/5 "2021-10-13T16:13:31Z")

</div>

Sorry for the confusion (if any); i modified the qn to add the fact that petName value can vary, but must be removed

---

<div class="post-metadata">

**Author:** ![AquaX](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aquax/32/92006_2.png) [@AquaX](https://discuss.elastic.co/u/AquaX)\
**Post date:** [October 13, 2021, 4:44pm UTC](https://discuss.elastic.co/t/grok-regex-pattern-for-symbols/286624/6 "2021-10-13T16:44:24Z")

</div>

I stand corrected.

---

<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:** [November 10, 2021, 4:45pm UTC](https://discuss.elastic.co/t/grok-regex-pattern-for-symbols/286624/7 "2021-11-10T16:45:22Z")

</div>

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