Skip to Main Content

SQL & PL/SQL

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.

Regexp way of getting the substring

RanagalApr 15 2019 — edited Apr 29 2019

Hello Experts,

I have this simple requirement:

input: 'one/two/three/four/five'

output: 'four/five' on providing 2

input: 'one/two/three/four/five'

output: 'five' on providing 1

Basically I will input the no of words that I want and I will have to extract them from the mail string. I have the below perfectly working code.

WITH inputs(val) AS

(SELECT 'one/two/three/four/five' FROM dual)
SELECT Ltrim(Substr(val, Instr(val, '/', -1, :user_input)), '/') AS val
FROM   inputs;

But I was just wondering if there is any regular expression solution that involves one pass.

For eg: regexp_substr(val,'pattern',whatever_is_necessary)

Eager to learn if there is one. Thanks in advance.

Oracle Version: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production

Regards,

Ranagal

 

This post has been answered by mathguy on Apr 17 2019
Jump to Answer
Comments
Post Details
Added on Apr 15 2019
17 comments
2,409 views