Search code examples
sqlhiveimpala

Hive query to get the value for a given key in String


I am using regexp_extract for getting sub-string from a string

My string is ":abd: 576892034 :erg: 94856023MXCI :oute: A RF WERS YUT :oowpo: 649217349GBT GB"

How will get this using regexp_extract function.

I need the value as 576892034 if i pass the key as abd Any other function also fine.


Solution

  • select
      regexp_extract(
        ':adb: 576892034 :erg: 94856023MXCI :oute: A RF WERS YUT :oowpo: 649217349GBT GB',
        ':oute: ((?:.(?!:))+)',
        1
      )
    

    manual : cloudera docs

    example of regex : regex101