regex – Oracle SQL: Extracting text between two characters

This is old skool. I love regular expressions and can understand them but get into an awful lot of trouble when I try to produce them. A bit like Spanish (for me). So this is just SQL INSTR / SUBSTR / REPLACE. I’m not expecting any upvotes…

WITH test_data (raw_text)
 AS 
  (SELECT '{ABCDE}{F1}' from dual UNION ALL
   SELECT '{GHIJ}{K12}' from dual 
  )
SELECT
 raw_text
,SUBSTR(raw_text,2,INSTR(raw_text,'}{')-2)              first_string
,REPLACE(SUBSTR(raw_text,INSTR(raw_text,'}{')+2),'}')   second_string
--these two from Tim's excellent answer
,regexp_substr(raw_text, '\{([^}]+)\}', 1,1,NULL,1) 
,regexp_substr(raw_text, '\{([^}]+)\}', 1,2,NULL,1)
FROM
 test_data
;

Demo

Read more here: Source link