How can I use regex to split a string, using a string as a delimiter?

I’m trying to split a string using a string as a delimiter, in an Oracle store procedure. I can use instr easily, but I’m trying to learn how to do this with regex, as I understand that it is powerful and efficient.

After reading some articles, I thought I could do this (expected result was “Hello“):

select regexp_substr('Hello My Delimiter World', '( My Delimiter )+', 1, 1)
from dual

Result:

My Delimiter

and (expected result was “World“):

  select regexp_substr('Hello My Delimiter World', '( My Delimiter )+', 1, 2)
    from dual

Result:

null

What is the correct regex_substr for this requirement?


Source: regex

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.