# Regexp parsing\_exception for \\\[mytag\\\]. Why do regexp escapes for \[, \], (, ), break the parser?

**URL:** <https://discuss.elastic.co/t/regexp-parsing-exception-for-mytag-why-do-regexp-escapes-for-break-the-parser/76717>\
**Category:** Elasticsearch\
**Created:** [February 28, 2017, 3:30am UTC](https://discuss.elastic.co/t/regexp-parsing-exception-for-mytag-why-do-regexp-escapes-for-break-the-parser/76717 "2017-02-28T03:30:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![foobarbaz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/foobarbaz/32/15422_2.png) [@foobarbaz](https://discuss.elastic.co/u/foobarbaz)\
**Post date:** [February 28, 2017, 3:30am UTC](https://discuss.elastic.co/t/regexp-parsing-exception-for-mytag-why-do-regexp-escapes-for-break-the-parser/76717/1 "2017-02-28T03:30:10Z")

</div>

Trying to use regexp to match a value in title that has surrounding [] or () characters however seeing an unexpected error when escaping these characters. Have tried both \[ and \\[, looking for some guidance.

```
'{
    "query": {
        "regexp":{
            "title": {
                "value": "\[mytag\]",
            }
        }
    }
}'

```

Seeing the following error:

```
{
  "error" : {
    "root_cause" : [
      {
        "type" : "parsing_exception",
        "reason" : "Failed to parse",
        "line" : 6,
        "col" : 26
      }
    ],
    "type" : "parsing_exception",
    "reason" : "Failed to parse",
    "line" : 6,
    "col" : 26,
    "caused_by" : {
      "type" : "json_parse_exception",
      "reason" : "Unrecognized character escape '[' (code 91)\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@3596d5c9; line: 6, column: 29]"
    }
  },
  "status" : 400
}
```

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [February 28, 2017, 9:51am UTC](https://discuss.elastic.co/t/regexp-parsing-exception-for-mytag-why-do-regexp-escapes-for-break-the-parser/76717/2 "2017-02-28T09:51:30Z")

</div>

Hi @foobarbaz,

for me it works fine with `\\`; see the following example (tested on Elasticsearch 5.2.1):

```auto
DELETE library

PUT library
{
   "mappings": {
      "quotes": {
         "properties": {
            "content": {
               "type": "text",
               "fields": {
                  "raw": {
                      "type": "keyword"
                  }
               }
            }
         }
      }
   }
}

POST /library/quotes
{
    "content": "Hello [here] I am"
}

GET /library/quotes/_search
{
    "query": {
        "regexp":{
            "content.raw": {
                "value": ".*\\[here\\].*"
            }
        }
    }
}

```

By the way, if you want to store something like tags, it might be worth checking whether you can index them as an [array](https://www.elastic.co/guide/en/elasticsearch/reference/master/array.html). Then there is no need for regexes.

Daniel

---

<div class="post-metadata">

**Author:** ![foobarbaz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/foobarbaz/32/15422_2.png) [@foobarbaz](https://discuss.elastic.co/u/foobarbaz)\
**Post date:** [March 23, 2017, 5:33pm UTC](https://discuss.elastic.co/t/regexp-parsing-exception-for-mytag-why-do-regexp-escapes-for-break-the-parser/76717/3 "2017-03-23T17:33:08Z")

</div>

Daniel,

Thanks so much for this! Worked and ended up taking your advice about arrays, per your advice took this approach.

Appreciate your time and help!

Cheers mate,  
Joshua

---

<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 20, 2017, 5:33pm UTC](https://discuss.elastic.co/t/regexp-parsing-exception-for-mytag-why-do-regexp-escapes-for-break-the-parser/76717/4 "2017-04-20T17:33:25Z")

</div>

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