# Query based string to match a regular expression

**URL:** <https://discuss.elastic.co/t/query-based-string-to-match-a-regular-expression/165077>\
**Category:** Elasticsearch\
**Created:** [January 21, 2019, 3:26pm UTC](https://discuss.elastic.co/t/query-based-string-to-match-a-regular-expression/165077 "2019-01-21T15:26:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxime\_houe](https://avatars.discourse-cdn.com/v4/letter/m/7993a0/32.png) [@maxime\_houe](https://discuss.elastic.co/u/maxime_houe)\
**Post date:** [January 21, 2019, 3:26pm UTC](https://discuss.elastic.co/t/query-based-string-to-match-a-regular-expression/165077/1 "2019-01-21T15:26:01Z")

</div>

Hello,

I know it is possible to make a regular expression query to match any string in a string based document on elasticsearch. But is it possible the other way around ? Can I make a query based on a string and match a regular expression saved in the document with elasticsearch ?

For instance, I create the following document via kibana :

```
POST /test1/type
{
  "input": "[0-9]+ ?kg",
  "output": "weight"
  
}

```

Can I make a query with the string "67kg" in order to match the regex and get this :

```
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "test1",
        "_type" : "type",
        "_id" : "XqXucGgBXOzlaMdqiLcI",
        "_score" : 1.0,
        "_source" : {
          "input" : "[0-9]+ ?kg",
          "output" : "weight"
        }
      }
    ]
  }
}
```

---

<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:** [February 18, 2019, 3:26pm UTC](https://discuss.elastic.co/t/query-based-string-to-match-a-regular-expression/165077/2 "2019-02-18T15:26:11Z")

</div>

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