As I understand it, you want to change
something~something~data^^something
to
data
where the first two somethings don't have ~ characters in them. I don't
know Oracle's regexp_replace. In sed I would do it in 2 steps for ease of
thinking, first get the third field and then trim it down.
Get the third field.
s/^[^~]*~[^~]*~\([^~]*\)~.*$/\1
translation,
^ match start of line
[^~] a character that is not ~
* change the last thing to 0 or more occurances, i.e. a run of characters
that is not ~
~ match a ~, the first field seperator
[^~]*~ as above, i.e. the second field and it's seperator
\( start capturing the characters we want
[^~]* the third field
\) stop capturing
~ the seperator at the end of the third field
.* matches anything
$ matches end of line
\1 the text captured in the first set of braces
Then to remove everything after the ^^, just
s/^^.*//
It is possible to put this into one replacement, but it is harder.