Search code examples
hiveimpala

Impala/Hive function to get the substring of a 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 576892034 if i pass :abd:


Solution

  • Try:

    REGEXP_EXTRACT('your string', ':abd: ([^:]+)', 1)
    

    The regexp :abd: ([^:]+) means match ':abd: ' folowed by any characters that are not ':'.

    This regexp assumes that ':' does not appears withing the "value" strings. As such, it would fail on this input:

    :abd: 5768:92034 :erg: 94856023MXCI :oute: A RF WERS YUT :oowpo: 649217349GBT GB