# Parse optional field with or without leading spaces

**URL:** <https://discuss.elastic.co/t/parse-optional-field-with-or-without-leading-spaces/76041>\
**Category:** Logstash\
**Created:** [February 22, 2017, 1:36pm UTC](https://discuss.elastic.co/t/parse-optional-field-with-or-without-leading-spaces/76041 "2017-02-22T13:36:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mflash](https://avatars.discourse-cdn.com/v4/letter/m/ecb155/32.png) [@mflash](https://discuss.elastic.co/u/mflash)\
**Post date:** [February 22, 2017, 1:36pm UTC](https://discuss.elastic.co/t/parse-optional-field-with-or-without-leading-spaces/76041/1 "2017-02-22T13:36:16Z")

</div>

hello,

i am trying to parse the following log messages with grok:

1. [2017-02-21T16:20:11.709Z] [debug] [mosaicresult] publish mosaicresult client id: gIsdfdsfgvdsfvdfs channel: localMosaicChannel **[{"ffvfv":"dfvfdvdfv"}]**
2. [2017-02-21T16:20:11.709Z] [debug] [mosaicresult] publish mosaicresult client id: gIsdfdsfgvdsfvdfs channel: localMosaicChannel

the last part that marked is optional .  
when it doesnt exist, there are no spaces at the end of log message , and when exits , there is.

the regexp used for both logs:  
[%{TIMESTAMP\_ISO8601:datetime}] [%{LOGLEVEL:level}] [%{NOTSPACE:serviceName}] %{GREEDYDATA:logMessage}(\s\*)([%{GREEDYDATA:meta}])?

problem: the result for the first log is that meta field is empty, that is the problem.

please advise.  
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:** [March 22, 2017, 1:36pm UTC](https://discuss.elastic.co/t/parse-optional-field-with-or-without-leading-spaces/76041/2 "2017-03-22T13:36:30Z")

</div>

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