# Help needed with Regular Expression search and special characters

**URL:** <https://discuss.elastic.co/t/help-needed-with-regular-expression-search-and-special-characters/52130>\
**Category:** Elasticsearch\
**Created:** [June 7, 2016, 10:13pm UTC](https://discuss.elastic.co/t/help-needed-with-regular-expression-search-and-special-characters/52130 "2016-06-07T22:13:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jrgns](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jrgns/32/640_2.png) [@jrgns](https://discuss.elastic.co/u/jrgns)\
**Post date:** [June 7, 2016, 10:13pm UTC](https://discuss.elastic.co/t/help-needed-with-regular-expression-search-and-special-characters/52130/1 "2016-06-07T22:13:14Z")

</div>

I'm trying to do a regex field on a not\_analyzed field that contain text that conform to the following:

`word word keyOne=(20),keyTwo=(30)`

I've tried various permutations to get a regexp query working to find documents with two or more numbers inside the round brackets after `keyOne`:

```
{
  "query": {
    "regexp": {
      "message_raw": "keyOne=\\([0-9]{2,}\\)"
    },
    "analyzer": "simple"
  }
}

```

This does not match:

```
{
  "_index" : "test",
  "_type" : "messages",
  "_id" : "AVUQAVW63lfkFHq9cox-",
  "matched" : false,
  "explanation" : {
    "value" : 0.0,
    "description" : "Failure to meet condition(s) of required/prohibited clause(s)",
    "details" : [ {
      "value" : 0.0,
      "description" : "no match on required clause (message_raw:/keyOne=\\([0-9]{2,}\\)/)",
      "details" : [ {
        "value" : 0.0,
        "description" : "message_raw:/keyOne=\\([0-9]{2,}\\)/ doesn't match id 0",
        "details" : []
      } ]
    }, {
      "value" : 0.0,
      "description" : "match on required clause, product of:",
      "details" : [ {
        "value" : 0.0,
        "description" : "# clause",
        "details" : []
      }, {
        "value" : 1.0,
        "description" : "_type:messages, product of:",
        "details" : [ {
          "value" : 1.0,
          "description" : "boost",
          "details" : []
        }, {
          "value" : 1.0,
          "description" : "queryNorm",
          "details" : []
        } ]
      } ]
    } ]
  }
}

```

The only match I could get, was the following:

```
{
  "query": {
    "regexp": {
      "message_raw": "[0-9]{2,}"
    },
    "analyzer": "simple"
  }
}

```

And the explanation:

```
{
  "_index" : "test",
  "_type" : "messages",
  "_id" : "AVUQAVW63lfkFHq9cox-",
  "matched" : true,
  "explanation" : {
    "value" : 1.0,
    "description" : "sum of:",
    "details" : [ {
      "value" : 1.0,
      "description" : "message_raw:/[0-9]{2,}/, product of:",
      "details" : [ {
        "value" : 1.0,
        "description" : "boost",
        "details" : []
      }, {
        "value" : 1.0,
        "description" : "queryNorm",
        "details" : []
      } ]
    }, {
      "value" : 0.0,
      "description" : "match on required clause, product of:",
      "details" : [ {
        "value" : 0.0,
        "description" : "# clause",
        "details" : []
      }, {
        "value" : 1.0,
        "description" : "_type:messages, product of:",
        "details" : [ {
          "value" : 1.0,
          "description" : "boost",
          "details" : []
        }, {
          "value" : 1.0,
          "description" : "queryNorm",
          "details" : []
        } ]
      } ]
    } ]
  }
}

```

I know it would be best to parse the message before sending it into Elasticsearch, but I'd still like to know why the regular expression doesn't work properly.

Any thoughts? Should I create an issue?

---

<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:** [July 5, 2017, 10:45pm UTC](https://discuss.elastic.co/t/help-needed-with-regular-expression-search-and-special-characters/52130/2 "2017-07-05T22:45:30Z")

</div>


