# Multiple matches in same line using grok

**URL:** <https://discuss.elastic.co/t/multiple-matches-in-same-line-using-grok/163637>\
**Category:** Logstash\
**Created:** [January 10, 2019, 12:54am UTC](https://discuss.elastic.co/t/multiple-matches-in-same-line-using-grok/163637 "2019-01-10T00:54:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ellje](https://avatars.discourse-cdn.com/v4/letter/e/7993a0/32.png) [@ellje](https://discuss.elastic.co/u/ellje)\
**Post date:** [January 10, 2019, 12:54am UTC](https://discuss.elastic.co/t/multiple-matches-in-same-line-using-grok/163637/1 "2019-01-10T00:54:41Z")

</div>

Hey guys, new-ish to Elastic and was hoping to get help for the following question.

To start off, I want to use logstash to parse a log file using grok statements.  
Say I have an input as follows:

**'Test failed with the following exception: Waiting for items to load: [selector: .do-something does.somethingElse, selector: do.another-thing, does.anotherThing... - '**

Currently, I could use the ' **selector:**' as the start , and ' **-**' as the end of the string captured, but within that I was hoping to get multiple matches in this same line. So in the end, I would like for the captured field to obtain:

_created\_field\_in\_elastic_: **.do-something does.somethingElse, do.another-thing, does.anotherThing.**

However, it only captures the first one. Is this where I use multiline? How do I get this?

---

<div class="post-metadata">

**Author:** ![Chris\_Lyons](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris_lyons/32/48107_2.png) [@Chris\_Lyons](https://discuss.elastic.co/u/Chris_Lyons)\
**Post date:** [January 12, 2019, 12:57am UTC](https://discuss.elastic.co/t/multiple-matches-in-same-line-using-grok/163637/2 "2019-01-12T00:57:09Z")

</div>

not sure what your config is but have you tried setting `break_on_match => false`? By default the GROK will exit as soon as a mach is made.

---

<div class="post-metadata">

**Author:** ![ellje](https://avatars.discourse-cdn.com/v4/letter/e/7993a0/32.png) [@ellje](https://discuss.elastic.co/u/ellje)\
**Post date:** [January 14, 2019, 5:52pm UTC](https://discuss.elastic.co/t/multiple-matches-in-same-line-using-grok/163637/3 "2019-01-14T17:52:04Z")

</div>

Yep, I do have that setting in there as well in the grok block

---

<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 14, 2019, 6:51pm UTC](https://discuss.elastic.co/t/multiple-matches-in-same-line-using-grok/163637/4 "2019-01-14T18:51:13Z")

</div>

It is unclear what you want in the created field. Do you want a string with the 4 things concatenated (which you can do using grok and mutate+gsub), or an array of 2 strings, or an array of 4 strings (both of which can be done using ruby).

---

<div class="post-metadata">

**Author:** ![ellje](https://avatars.discourse-cdn.com/v4/letter/e/7993a0/32.png) [@ellje](https://discuss.elastic.co/u/ellje)\
**Post date:** [January 14, 2019, 10:18pm UTC](https://discuss.elastic.co/t/multiple-matches-in-same-line-using-grok/163637/5 "2019-01-14T22:18:18Z")

</div>

Preferably an array of 4 strings. So I should use ruby like this? [https://jenkinsci.github.io/job-dsl-plugin/#method/javaposse.jobdsl.dsl.helpers.step.StepContext.ruby](https://jenkinsci.github.io/job-dsl-plugin/#method/javaposse.jobdsl.dsl.helpers.step.StepContext.ruby)

---

<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 14, 2019, 10:35pm UTC](https://discuss.elastic.co/t/multiple-matches-in-same-line-using-grok/163637/6 "2019-01-14T22:35:51Z")

</div>

Try something like

```
grok { match => { "message" => "selector: %{DATA:foo} - " } }
mutate {
    gsub => [
        "foo", ", selector: ", " ",
        "foo", ", ", " "
    ]
}
mutate { split => { "foo" => " " } }
```

---

<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 11, 2019, 10:40pm UTC](https://discuss.elastic.co/t/multiple-matches-in-same-line-using-grok/163637/7 "2019-02-11T22:40:51Z")

</div>

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