Retrivieng specific occurrences of a given Regex with Oracle SQL -


in simplified form, i'm attempting retrieve either first occurrence of '.*?=(.*?);.*' regex, or second, or third -- is, either x or y or z (that is, want able hardcode in query want first, second or third values) in following example:

select regexp_replace(   'margin=x;margin=y;margin=z;',   '.*?=(.*?);.*',   '\1',   1 -- occurrences. thought picking 1, 2 or 3 solve problem? ) dual;  -- returns "xyz", terrible. expecting return "x", in case. 

looking @ oracle documentation, thought relatively straightforward, last parameter (occurrences), apparently allows me select groups take consideration. doesn't! why?

thanks

i´m goingoff completly different solution. combining hierarchial substring select regexp_replace option needs?

this way create option either select 1 or multiple values, depending on needs. wouldn´t need write concatinating regex value , adjust select bit more needs

select regexp_replace(subselect.val, '.*=(.*?);', '\1') -- remove "margin=" (select regexp_substr(              'margin=x;margin=y;margin=z;',              '.*?=(.*?);',              1,              level) val,              level lvl       dual       connect regexp_substr('margin=x;margin=y;margin=z;',                               '.*?=(.*?);',                               1,                               level) not null) subselect -- select represents each margin=t single row lvl = 1; -- cou define multiple values select aswell. 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -