# Escaping backslash in grok pattern giving error

**URL:** <https://discuss.elastic.co/t/escaping-backslash-in-grok-pattern-giving-error/171300>\
**Category:** Elasticsearch\
**Created:** [March 7, 2019, 12:26pm UTC](https://discuss.elastic.co/t/escaping-backslash-in-grok-pattern-giving-error/171300 "2019-03-07T12:26:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pk.241011](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pk.241011/32/86285_2.png) [@pk.241011](https://discuss.elastic.co/u/pk.241011)\
**Post date:** [March 7, 2019, 12:26pm UTC](https://discuss.elastic.co/t/escaping-backslash-in-grok-pattern-giving-error/171300/1 "2019-03-07T12:26:21Z")

</div>

This is the message I am working with:

```
C:\Data\Projects\Demo\2019-03-06-14-35-07_check.log

```

In the grok debugger this was the pattern I checked and it worked.

```
%{PATH:dontwant}\\%{USERNAME:identifier}_%{GREEDYDATA:drop} 

```

Output:

```
{
  "drop": "check.log",
  "identifier": "2019-03-06-14-35-07",
  "dontwant": "C:\\Data\\Projects\\Demo"
}

```

Now I wanted to put this in my pipeline. But I am seeing errors.

For this:

```
{
      "grok": {
        "field": "FileName",
        "patterns": ["%{PATH:dontwant}\\%{USERNAME:identifier}_%{GREEDYDATA:drop}"]
      }
    },

```

I get error:

```
{
  "error": {
"root_cause": [
  {
    "type": "parse_exception",
    "reason": "[patterns] Invalid regex pattern found in: [%{PATH:dontwant}\\%{USERNAME:identifier}_%{GREEDYDATA:drop}]. unmatched close parenthesis",
    "header": {
      "processor_type": "grok",
      "property_name": "patterns"
    }
  }
],
"type": "parse_exception",
"reason": "[patterns] Invalid regex pattern found in: [%{PATH:dontwant}\\%{USERNAME:identifier}_%{GREEDYDATA:drop}]. unmatched close parenthesis",
"header": {
  "processor_type": "grok",
  "property_name": "patterns"
}
  },
  "status": 400
}

```

For this:

```
{
      "grok": {
        "field": "FileName",
        "patterns": ["%{PATH:dontwant}\%{USERNAME:identifier}_%{GREEDYDATA:drop}"]
      }
    },

```

I get error:

```
{
  "error": {
    "root_cause": [
      {
        "type": "parse_exception",
        "reason": "Failed to parse content to map"
      }
    ],
    "type": "parse_exception",
    "reason": "Failed to parse content to map",
    "caused_by": {
      "type": "i_o_exception",
      "reason": "Unrecognized character escape '%' (code 37)\n at [Source: org.elasticsearch.common.bytes.BytesReference$MarkSupportingStreamInputWrapper@1b5eba15; line: 33, column: 41]"
    }
  },
  "status": 400
}

```

Any pointers on how I can make it work?

---

<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:** [April 4, 2019, 12:26pm UTC](https://discuss.elastic.co/t/escaping-backslash-in-grok-pattern-giving-error/171300/2 "2019-04-04T12:26:23Z")

</div>

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