Parado's regular expression matches everything that's not a comma multiple times followed by a carriage return. This means it won't work for a line-feed or if there's a comma in the text.
Oracle supports multi-line expressions using the m
match parameter. When using this mode, $
matches the end of each line as well as the end of the string. You can use this to simply the expression massively to:
regexp_substr(str, '.*$', 1, 1, 'm')
That is match the first occurrence (the first line) of the string that matches anything, followed by the end of the string, counting from the first character.
As an example:
with strings as (
select 'hi
hi again' as str
from dual
union all
select 'bye
and again'
from dual
)
select regexp_substr(str, '.*$', 1, 1, 'm')
from strings