Major Major Major Major - 6 months ago 54
SQL Question

Oracle Regexp - substr by multiple spaces but not single space

Lets say I have a string-

"a b cc d d e"

I'd like to be able to do

regexp_substr('a b cc d d e', ??, 1, 4)

And have it return "d d".

I was using "[^ ]+" as my pattern, but it splits single spaces which I don't want.


I think this will do what you want:

select regexp_substr(col, '([^ ]*[ ]?[^ ]+)+', 1, 4)