# Is this regular expression correct?

**URL:** https://discuss.elastic.co/t/is-this-regular-expression-correct/56575
**Category:** Elasticsearch
**Created:** [July 28, 2016, 1:44am UTC](https://discuss.elastic.co/t/is-this-regular-expression-correct/56575 "2016-07-28T01:44:25Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Geunmoon\_Oh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/geunmoon_oh/32/7507_2.png) [@Geunmoon\_Oh](https://discuss.elastic.co/u/Geunmoon_Oh)
#### Post date: [July 28, 2016, 1:44am UTC](https://discuss.elastic.co/t/is-this-regular-expression-correct/56575/1 "2016-07-28T01:44:25Z")

</div>

i made index and inserted a document about phone number like below

```
# curl -XPOST localhost:9200/testindex?pretty -d '{
> "mappings": {
> "document": {
> "properties": {
> "name": {
> "type": "string"
> }
> }
> }
> }
> }'
{
  "acknowledged" : true
}
# curl -XPUT localhost:9200/testindex/document/1?pretty -d '{"name": "010-1111-2222"}'
{
  "_index" : "testindex",
  "_type" : "document",
  "_id" : "1",
  "_version" : 1,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "failed" : 0
  },
  "created" : true
}
```

And, i searched with regular expression. but no found..  
what is wrong??

```
# curl -XGET localhost:9200/testindex/document/_search?pretty -d '{
> "query": {
> "query_string": {
> "query": "name:/010-[0-9]{4}-[0-9]{4}/"
> }
> }
> }'
{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 10,
    "successful" : 10,
    "failed" : 0
  },
  "hits" : {
    "total" : 0,
    "max_score" : null,
    "hits" : []
  }
}
```

---

<div class="post-metadata">

### Author: ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)
#### Post date: [July 28, 2016, 2:29am UTC](https://discuss.elastic.co/t/is-this-regular-expression-correct/56575/2 "2016-07-28T02:29:46Z")

</div>

Regexes match whole terms. Configure the phone numbers as not\_analzed and  
it should work. Also, I try to strip the formatting from.phone numbers and  
add the country code. It saves a lot of trouble if you ever have to deal  
with numbers with other country codes.

---

<div class="post-metadata">

### Author: ![Geunmoon\_Oh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/geunmoon_oh/32/7507_2.png) [@Geunmoon\_Oh](https://discuss.elastic.co/u/Geunmoon_Oh)
#### Post date: [July 28, 2016, 5:15am UTC](https://discuss.elastic.co/t/is-this-regular-expression-correct/56575/3 "2016-07-28T05:15:37Z")

</div>

Thank you. it was done.  
i knew default is not\_analzed for target field.

---

<div class="post-metadata">

### Author: ![Geunmoon\_Oh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/geunmoon_oh/32/7507_2.png) [@Geunmoon\_Oh](https://discuss.elastic.co/u/Geunmoon_Oh)
#### Post date: [July 28, 2016, 5:35am UTC](https://discuss.elastic.co/t/is-this-regular-expression-correct/56575/4 "2016-07-28T05:35:01Z")

</div>

but, if i insert more document like below,  
curl -XPUT localhost:9200/testindex/document/1?pretty -d '{"name": "Bob 010-1111-2222"}'

is it also included in result ??  
i tested it. but it's not included.

---

<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:32pm UTC](https://discuss.elastic.co/t/is-this-regular-expression-correct/56575/5 "2017-07-05T22:32:19Z")

</div>


