Grok parser to return only numbers

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

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

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

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

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