SQL Oracle | How would I select a substring where it begins with a certain letter and ends with a certain symbol? -


if had this:

name        eyes==id==hair jon         brown==f9182==red may         blue==f10100==brown bill        hazel/green==f123==brown 

...and wanted create new id column id alone, , know everyone's id starts 'f' , end @ '=' how select substring compact column , take id out?

ex. want end product

name        eyes==id==hair               id jon         brown==f9182==red            f9182 may         blue==f10100==brown          f10100 bill        hazel/green==f123==brown     f123 

if can't make end @ '=' there way trim rest of content isn't part of id after selecting it?

you can use regular expression:

regexp_substr('hazel/green==f123==brown','(==f.+?==)') 

extracts '==f123==', trim =:

ltrim(rtrim(regexp_substr('hazel/green==f123==brown','(==f.+?==)'), '='), '=') 

if oracle supported lookahead/lookbehind easier...

edit:

base on @erkanhaspulat's query don't need ltrim/rtrim can specify return first capture group (i forget that). safe should change regex not greedy:

regexp_substr('hazel/green==f123==brown==iii','==(.+?)==', 1, 1, null, 1) 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -