Search code examples
postgresqlregexp-substr

postgresql : regexp_substr - get sub string between occurrence of delimiters


I have these strings:

[{"Name":"id","Value":"Window_Ex_kebklipecbcegiocpa_widget_open"
[{"Name":"id","Value":"Window_Ex_kebklipecbcegiocpa_widget_close"
[{"Name":"id","Value":"Window_Ex_kebklipecbcegiocpa_widget_mid_value"

and I'm trying to extract only the parts after the third _, until the end of the string (which ends always with ")

widget_open
widget_close
widget_mid_value

I'm using postgresql, and wanted to use the regexp_substr syntax, in order to extract it. Thanks!


Solution

  • regexp_replace(data::text,'^([^_]+_){3}','')

    You can try

    select regexp_replace(data::text,'^([^_]+_){3}','')
      from (
          select 'one_two_three_four  s'::text as data 
          union select 'a_bb_ccc_dddd_eeee_ffff'
      ) data
    

    enter image description here