# Query with regular expression special characters

**URL:** https://discuss.elastic.co/t/query-with-regular-expression-special-characters/200195
**Category:** Elasticsearch
**Created:** [September 19, 2019, 11:37am UTC](https://discuss.elastic.co/t/query-with-regular-expression-special-characters/200195 "2019-09-19T11:37:03Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![evalufran](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/evalufran/32/53286_2.png) [@evalufran](https://discuss.elastic.co/u/evalufran)
#### Post date: [September 19, 2019, 11:37am UTC](https://discuss.elastic.co/t/query-with-regular-expression-special-characters/200195/1 "2019-09-19T11:37:03Z")

</div>

HI everyone!  
I have a lot of fields with XML text and i want to make a query to check if some tags are closed.  
In order to do that i'm using the whitespace analyzer (so that i can query for char like "\<").

Assuming that i have a field like this one  
`"example": "<attribute>hi</attribute>"`

i tried to query for :

```
GET myindex/_search
{
    "query": {
        "regexp": {
            "example": { 
                "value": "</attribute>",
                "flags" : "NONE",
                "max_determinized_states": 10000,
                "rewrite": "constant_score"
            }
        }
    }
}

```

And i get no hits for it.  
I tried to query for attribute and i get the hit...  
I tried to query for "\<" char like this:

```
GET prova/_search
{
    "query": {
        "regexp": {
            "ved": { 
                "value": "'<'",
                "flags" : "NONE",
                "max_determinized_states": 10000,
                "rewrite": "constant_score"
            }
        }
    }
}

```

i get no hits... i know i'm probably doing something wrong but i can't understand what..  
can someone give me an advice?

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [September 19, 2019, 1:23pm UTC](https://discuss.elastic.co/t/query-with-regular-expression-special-characters/200195/2 "2019-09-19T13:23:42Z")

</div>

my assumption here (that could be validated if this was a reproducible example including the index creation and document indexing), is that your field is analyzed and thus does not contain the term '' anymore. You could try using the keyword field

```auto
PUT myindex/_doc/1
{
  "example" : "<attribute>hi</attribute>"
}

GET myindex/_mapping

GET myindex/_search
{
  "query": {
    "regexp": {
      "example.keyword": {
        "value": ".*\\</attribute\\>"
      }
    }
  }
}

```

Note that I would always try to refrain from regexp queries, so maybe adding some more context to get rid of it might be another idea.

---

<div class="post-metadata">

### Author: ![evalufran](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/evalufran/32/53286_2.png) [@evalufran](https://discuss.elastic.co/u/evalufran)
#### Post date: [September 19, 2019, 1:40pm UTC](https://discuss.elastic.co/t/query-with-regular-expression-special-characters/200195/3 "2019-09-19T13:40:19Z")

</div>

Thank you very very very much!!!

---

<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: [October 17, 2019, 1:52pm UTC](https://discuss.elastic.co/t/query-with-regular-expression-special-characters/200195/4 "2019-10-17T13:52:43Z")

</div>

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