Rajat Arora
Rajat Arora

Reputation: 41

Extracting email_address from a string in hive

I am new to hive I have a string and I want to extract the email address from that string in hive

Select regexp_extract('my email address is [email protected]', '@(.*)',0);
OK
@gmail.com

It is only extracting the domain name but I need the full email address i.e. '[email protected]'

I an new to regex

Upvotes: 0

Views: 567

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626699

You can use

Select regexp_extract('my email address is [email protected]', '\\S+@\\S+',0);
Select regexp_extract('my email address is [email protected]', '\\S+@\\S+\\.\\S+',0);

Note the double backslashes since to denote a literal backslash in text you need to use two in the string literal.

The \S+@\S+ pattern simply matches one or more non-whitespace chars, @, and then again one or more non-whitespace chars.

The \S+@\S+\.\S+ pattern does the same + it also then matches a . and again one or more non-whitespace chars.

Upvotes: 1

Related Questions