# Grok space expression optional

**URL:** <https://discuss.elastic.co/t/grok-space-expression-optional/152631>\
**Category:** Logstash\
**Created:** [October 16, 2018, 10:48am UTC](https://discuss.elastic.co/t/grok-space-expression-optional/152631 "2018-10-16T10:48:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rotem\_lom](https://avatars.discourse-cdn.com/v4/letter/r/54ee81/32.png) [@rotem\_lom](https://discuss.elastic.co/u/rotem_lom)\
**Post date:** [October 16, 2018, 10:48am UTC](https://discuss.elastic.co/t/grok-space-expression-optional/152631/1 "2018-10-16T10:48:45Z")

</div>

Hi there,  
In my environments I have the following log files:

> ```
> Domain name: WORKGROUP
> Console user name:Administrator
> Console user groups: [Administrators,]
> Logged in users: [Administrator,]
> OS version: Windows 10
> OS Platform: x64
> Current System Time:2018-08-06T04:14:32-07:00
> 
> ```

And I use this grok match to parse this line(line by line):

> ```
> grok {
> match => { "message" => "%{GREEDYDATA:key_info}:%{GREEDYDATA:value_info}" }
> }
> 
> ```

All the line parse well except for the last line,  
the problem in this line is the 'space' - as you can see all the line have space between ':' to the value, and in the last line the ':' connected to value.  
How can I making a part in the grok expression optional?  
Thanks

---

<div class="post-metadata">

**Author:** ![Jenni](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jenni/32/29684_2.png) [@Jenni](https://discuss.elastic.co/u/Jenni)\
**Post date:** [October 18, 2018, 12:40pm UTC](https://discuss.elastic.co/t/grok-space-expression-optional/152631/2 "2018-10-18T12:40:41Z")

</div>

An optional space would be \s?  
But you have another problem: Your value contains ':', so the first GREEDYDATA includes way too much:

```
{
  "key_info": [
    [
      "Current System Time:2018-08-06T04:14:32-07"
    ]
  ],
  "value_info": [
    [
      "00"
    ]
  ]
}

```

Try

`(?<key_info>[^:]*):\s?%{GREEDYDATA:value_info}`  
(The key may contain any character but a colon.)

or

`(?<key_info>.*?):\s?%{GREEDYDATA:value_info}`  
(The key may contain any character, but as little as possible.)

---

<div class="post-metadata">

**Author:** ![rotem\_lom](https://avatars.discourse-cdn.com/v4/letter/r/54ee81/32.png) [@rotem\_lom](https://discuss.elastic.co/u/rotem_lom)\
**Post date:** [October 21, 2018, 12:34pm UTC](https://discuss.elastic.co/t/grok-space-expression-optional/152631/3 "2018-10-21T12:34:06Z")

</div>

> [@Jenni](#):
>
> (?\<key\_info\>[^:]\*):\s?%{GREEDYDATA:value\_info}

The first one work great !  
Thanks!

---

<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 18, 2018, 12:34pm UTC](https://discuss.elastic.co/t/grok-space-expression-optional/152631/4 "2018-11-18T12:34:11Z")

</div>

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