Support Questions

Find answers, ask questions, and share your expertise
Announcements
Check out our newest addition to the community, the Cloudera Data Analytics (CDA) group hub.

Hive to extract multiple ip addresses from a string

Expert Contributor

Hi All,

I have a string

String:
some text with an ip 111.111.111.111 and a decimal 11.2323232 and some text here and then an int 1 and then some HTTP/1.1 with a 503 request and then another ip 222.222.222.222 and some imaginary 999.999.999.999

I want to output all the ip addresses in comma saperated. I tried the below

select regexp_replace(regexp_replace(String,'[^(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})]',' '),'\\s+',',');
+------------------------------------------------------------------------+--+
|                                  _c0                                   |
+------------------------------------------------------------------------+--+
| ,111.111.111.111,11.2323232,1,1.1,503,222.222.222.222,999.999.999.999  |
+------------------------------------------------------------------------+--+

Expected output is : 111.111.111.111,222.222.222.222,999.999.999

Could you please help me

1 ACCEPTED SOLUTION

Are you familiar with user defined functions?

View solution in original post

2 REPLIES 2

Expert Contributor

@Shu can you please help me

Are you familiar with user defined functions?

Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.