# LogStash Config File - Grok Regex

**URL:** <https://discuss.elastic.co/t/logstash-config-file-grok-regex/231016>\
**Category:** Logstash\
**Created:** [May 4, 2020, 6:22pm UTC](https://discuss.elastic.co/t/logstash-config-file-grok-regex/231016 "2020-05-04T18:22:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karanbir\_Mann](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/karanbir_mann/32/66787_2.png) [@Karanbir\_Mann](https://discuss.elastic.co/u/Karanbir_Mann)\
**Post date:** [May 4, 2020, 6:22pm UTC](https://discuss.elastic.co/t/logstash-config-file-grok-regex/231016/1 "2020-05-04T18:22:56Z")

</div>

Hello Community,

I'm very new to LogStash and I have a question. I am trying to use grok to get a substring from my message and put it in a new field. I've used grokdebugger in kibana and it seems to highlight the right text.  
This is my grok pattern: ` (?<CR Number>(?<=CR num:)".{0,20}?")`

What is the right way to put this grok pattern in config file? I am expecting it to create a new CR Number field. Right now I am doing this, but it does not work:

```auto
if [type] == "esign" 
  {
    grok {
    
      match => { "message" => "(?<CR Number>(?<=CR num:)".{0,20}?")" }
    }

```

Am I putting the grok regex pattern in config file the right way?  
Thanks in advance!

Karanbir Mann

---

<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:** [May 5, 2020, 3:36pm UTC](https://discuss.elastic.co/t/logstash-config-file-grok-regex/231016/2 "2020-05-05T15:36:29Z")

</div>

> [@Karanbir\_Mann](#):
>
> "(?(?\<=CR num:)".{0,20}?")"

I would expect logstash to log an error for that. If you have double quotes in your pattern then use single quotes around it

```
'(?<CR Number>(?<=CR num:)".{0,20}?")'

```

---

<div class="post-metadata">

**Author:** ![Karanbir\_Mann](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/karanbir_mann/32/66787_2.png) [@Karanbir\_Mann](https://discuss.elastic.co/u/Karanbir_Mann)\
**Post date:** [May 5, 2020, 5:20pm UTC](https://discuss.elastic.co/t/logstash-config-file-grok-regex/231016/3 "2020-05-05T17:20:26Z")

</div>

Hi @Badger,

Amazing suggestion. I actually just solved my issue by escaping my double quotes using backslash and it solved the issue.

Thanks  
Karanbir

---

<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:** [June 2, 2020, 5:25pm UTC](https://discuss.elastic.co/t/logstash-config-file-grok-regex/231016/4 "2020-06-02T17:25:24Z")

</div>

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