# Grok parser to return only numbers

**URL:** https://discuss.elastic.co/t/grok-parser-to-return-only-numbers/94294
**Category:** Logstash
**Created:** [July 24, 2017, 9:35am UTC](https://discuss.elastic.co/t/grok-parser-to-return-only-numbers/94294 "2017-07-24T09:35:27Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Ravi\_Shanker\_Reddy](https://avatars.discourse-cdn.com/v4/letter/r/a5b964/32.png) [@Ravi\_Shanker\_Reddy](https://discuss.elastic.co/u/Ravi_Shanker_Reddy)
#### Post date: [July 24, 2017, 9:35am UTC](https://discuss.elastic.co/t/grok-parser-to-return-only-numbers/94294/1 "2017-07-24T09:35:27Z")

</div>

I have a field where I will get phone number. Here are the examples.

1-800-1234  
1(800)1234  
18001234  
1 800 1234

If the format is matching anyone I want to save the number in ES like 18001234. Can anyone help for the grok pattern

---

<div class="post-metadata">

### Author: ![CDR](https://avatars.discourse-cdn.com/v4/letter/c/d9b06d/32.png) [@CDR](https://discuss.elastic.co/u/CDR)
#### Post date: [July 24, 2017, 6:02pm UTC](https://discuss.elastic.co/t/grok-parser-to-return-only-numbers/94294/2 "2017-07-24T18:02:34Z")

</div>

```
grok{
     match => {"message" => ["%{INT:first} ?(-|\()?%{INT:second} ?(-|\))?%{INT:third}"]
     }
}
mutate{
     add_field => {
         "number"=>"%{first}%{second}%{third}"
     }
}
```

---

<div class="post-metadata">

### Author: ![Ravi\_Shanker\_Reddy](https://avatars.discourse-cdn.com/v4/letter/r/a5b964/32.png) [@Ravi\_Shanker\_Reddy](https://discuss.elastic.co/u/Ravi_Shanker_Reddy)
#### Post date: [July 25, 2017, 6:21am UTC](https://discuss.elastic.co/t/grok-parser-to-return-only-numbers/94294/3 "2017-07-25T06:21:20Z")

</div>

```
filter {
  mutate {
    gsub => [
      "number", "[\s(-]", ""
    ]
  }
}

```

I found out this. Which one is better to use???

---

<div class="post-metadata">

### Author: ![CDR](https://avatars.discourse-cdn.com/v4/letter/c/d9b06d/32.png) [@CDR](https://discuss.elastic.co/u/CDR)
#### Post date: [July 25, 2017, 12:06pm UTC](https://discuss.elastic.co/t/grok-parser-to-return-only-numbers/94294/4 "2017-07-25T12:06:41Z")

</div>

Yours may be a touch more efficient. Use whichever one makes the most sense to you. That way if you need to change/adjust it you are confident in what is happening

---

<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: [August 22, 2017, 12:07pm UTC](https://discuss.elastic.co/t/grok-parser-to-return-only-numbers/94294/5 "2017-08-22T12:07:04Z")

</div>

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