Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Oracle Regular Expression

User_AS6XDSep 17 2021

Input string: 'Chesterton, Mark;#789;#Erbach, Magnus;#786'
Output:Mark(no spaces before Mark)(Basically want to fetch everything between first comma and first semicolon excluding initial whitespaces)
Input String: Phillips, Edward;#744;#Bubba, Matthew;#782;#Mahony, Chloe;#779
Output:Edward
Input String: Corbett, Paul;#784;#Johnson, Ben;#392;#Smith, Adam;#775
Output:Paul

Kindly help.

This post has been answered by cormaco on Sep 17 2021
Jump to Answer

Comments

cormaco
Answer

Here is one way:

with input_string(ins) as (
    select 'Chesterton, Mark;#789;#Erbach, Magnus;#786' from dual union all
    select 'Phillips, Edward;#744;#Bubba, Matthew;#782;#Mahony, Chloe;#779' from dual union all
    select 'Corbett, Paul;#784;#Johnson, Ben;#392;#Smith, Adam;#775' from dual
)
select regexp_substr(ins,',\ *([^;]+)',1,1,null,1) regex from input_string

REGEX               
--------------------
Mark                
Edward              
Paul
                
Marked as Answer by User_AS6XD · Oct 14 2021
1 - 1

Post Details

Added on Sep 17 2021
1 comment
84 views