# How to match a sentence that may contain delimiter

**URL:** <https://discuss.elastic.co/t/how-to-match-a-sentence-that-may-contain-delimiter/220070>\
**Category:** Logstash\
**Created:** [February 20, 2020, 2:39am UTC](https://discuss.elastic.co/t/how-to-match-a-sentence-that-may-contain-delimiter/220070 "2020-02-20T02:39:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kingjherold](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kingjherold/32/62981_2.png) [@kingjherold](https://discuss.elastic.co/u/kingjherold)\
**Post date:** [February 20, 2020, 2:39am UTC](https://discuss.elastic.co/t/how-to-match-a-sentence-that-may-contain-delimiter/220070/1 "2020-02-20T02:39:36Z")

</div>

This is the log line

> msg: Malware/Virus detected - Rtf.Exploit.CVE\_2017\_11882-6584355-0:Message denied for delivery:Announcement: Holiday Tomorrow

This is where i'm figuring out how to match the "Announcement: Holiday Tomorrow" or "Announcement Holiday Tomorrow" part of the log. It can have colon or not. At the moment i don't have the right pattern. I'm new to logstash.

```
grok {

    match {

        "msg" => "%{[^:]+$}:%{GREEDYDATA:headerSubject}"

    }

}

```

---

<div class="post-metadata">

**Author:** ![ITIC](https://avatars.discourse-cdn.com/v4/letter/i/90ced4/32.png) [@ITIC](https://discuss.elastic.co/u/ITIC)\
**Post date:** [February 20, 2020, 6:49am UTC](https://discuss.elastic.co/t/how-to-match-a-sentence-that-may-contain-delimiter/220070/2 "2020-02-20T06:49:04Z")

</div>

Hi

If all messages have this exact same format, you could use "Announcement" as a separator of sorts:

```auto
grok { match { "msg" => "%{[^:]+$}:Announcement%{GREEDYDATA:headerSubjectTMP}" } }

```

And then you can `mutate{}` your `headerSubjectTMP` into the desired `headerSubject` and `remove_field => ["headerSubjectTMP"]`.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![kingjherold](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kingjherold/32/62981_2.png) [@kingjherold](https://discuss.elastic.co/u/kingjherold)\
**Post date:** [February 21, 2020, 1:40am UTC](https://discuss.elastic.co/t/how-to-match-a-sentence-that-may-contain-delimiter/220070/3 "2020-02-21T01:40:52Z")

</div>

Actually it will not be the same format. but i got the idea from you. I modified my log to have a "Subject - " part instead. so logstash config can be simple

> msg: Malware/Virus detected - Rtf.Exploit.CVE\_2017\_11882-6584355-0:Message denied for delivery: Subject - Announcement: Holiday Tomorrow

```
grok {

  match {

    "msg" => "Subject - %{GREEDYDATA:headerSubject}"

  }

}

```

Thank you!

---

<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:** [March 20, 2020, 1:41am UTC](https://discuss.elastic.co/t/how-to-match-a-sentence-that-may-contain-delimiter/220070/4 "2020-03-20T01:41:07Z")

</div>

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