用于hive的twitter数据的regex

3b6akqbq  于 2021-06-25  发布在  Hive
关注(0)|答案(1)|浏览(435)

我有以下推特数据。
数据分为两部分:

@Username

以及tweet或文本:

RT @username: Stay behind, or take the jump (anything in text or tags and emoji)#@name

@姓名jjjjj dhdkeueh sjdyeh@kdudiwi。。。。。

RT @username: thehdydvekdgeke

Hshedhdkdjfnfjfkfmhdkalshsh公司+£) #&#(#(£63+kdjdj??☺?☺? rt@username:这首歌叫kdudhekh juygg jyttt hyyg

£jdhdieo+3-)£) 7——uuueoehrmwowyeheldyejelwyej

Djyegeleisyhekelsudhewksi公司
这是数据,我想把数据分成两部分,第一部分是用户名,第二部分是tweet。
我做的正则表达式是:

^(RT\s[^ ]*)\s([\W]*[\H]*[\w\s@#;:!?+(+-_#)]*)$

第一部分有效,但第二部分无效。
有人能帮我吗?

hfyxw5xn

hfyxw5xn1#

with your_data as (
 select 'RT @username: Stay behind, or take the jump (anything in text or tags and emoji)' as str
 )

 select regexp_extract(str,'^RT\\s(\\S*)\\s(.*)$',1) as username, 
        regexp_extract(str,'^RT\\s(\\S*)\\s(.*)$',2) as tweet
    from your_data;

结果:

OK
username        tweet
@username:      Stay behind, or take the jump (anything in text or tags and emoji)
Time taken: 1.092 seconds, Fetched: 1 row(s)

使用 '^RT\\s(\\S*):\\s(.*)$' 如果您不想在用户名中使用“:”。
或者 '^RT\\s(\\S*):?\\s(.*)$' 如果 : 是可选的:

with your_data as (
 select 'RT @username Stay behind, or take the jump (anything in text or tags and emoji)' as str
 )

 select regexp_extract(str,'^RT\\s(\\S*):?\\s(.*)$',1) as username, 
        regexp_extract(str,'^RT\\s(\\S*):?\\s(.*)$',2) as tweet
    from your_data;

结果:

OK
username        tweet
@username       Stay behind, or take the jump (anything in text or tags and emoji)
Time taken: 28.587 seconds, Fetched: 1 row(s)

相关问题