Reputation: 103
I'm working on a substring regular expression and I need to get all characters from a string like this:
FIRSTCOLUMN, SECONDCOLUMN, THIRDCOLUMN
So far I've got:
SELECT
REGEXP_SUBSTR('FIRSTCOLUMN, SECONDCOLUMN, THIRDCOLUMN', '[^SECONDCOLUMN]+') AS SUBSTRING
FROM DUAL;
This returns just "FIR" but I need the result to be "FIRSTCOLUMN, ".
Another example to understand better the question is:
when I have '[^THIRDCOLUMN]+'
pattern instead of '[^SECONDCOLUMN]+'
as the first example, I want the result to be "FIRSTCOLUMN, SECONDCOLUMN, ".
I know it is possible but I'm not good enough on regular expressions.
Upvotes: 0
Views: 2709
Reputation: 43169
You are getting basic regular expressions concepts wrong. The [^...]
negates all characters inside the class, so it looks for characters not S
, not E
, not C
, etc which correctly stops at FIRST (see the S
).
What you possibly want is a lazy quantifier:
^.*?SECONDCOLUMN
or
^.*?THIRDCOLUMN
respectively.
Upvotes: 2