Major Major Major Major - 1 year ago 89
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.

Answer Source

I think this will do what you want:

select regexp_substr(col, '([^ ]*[ ]?[^ ]+)+', 1, 4)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download