Skip to main content

Hello

Imagine I have the following text:

 

⌗USA and ⌗Brazil are great places to live

 

And I want to extract only the word next to the #. In case that we have more than 2 #, then bring all ⌗words

 

How would the Regex expression look like? I tried this

 

REGEXP_EXTRACT([snippet],'(#\S+)')

 

but it only brings me ⌗USA

 

Regex Extract hashtags 

Thanks in advance

Rodrigo

4 件の回答
  1. 2022年7月29日 22:56

    HI Rodrigo,

    Understand...however, the Regex in Tableau (so far as I've seen) doesn't support a looping or iterative process to allow for multiple word patterns to be pulled from a string/sub-string. So your best bet at that point would be to split on the # and then concatenate back again...or you could use this hacky method of nested IFNULL's to get up to two # hashtag words out of a string:

    IFNULL('#'+STR(IFNULL(REGEXP_EXTRACT([Data],'(?:.*?#){1}(\w+)'),REGEXP_EXTRACT([Data],'#(\w+)')))

    +', #'+STR(REGEXP_EXTRACT([Data],'(?:.*?#){2}(\w+)')), '#'+STR(REGEXP_EXTRACT([Data],'#(\w+)')))

    Which would return the following:

    HI Rodrigo,Understand...however, the Regex in Tableau (so far as I've seen) doesn't support a looping or iterative process to allow for multiple word patterns to be pulled from a string/sub-string.I guess just repeat the ifnull segments for as many possible iterations that might be in the data?

     

    Best, Don

0/9000