ZerOne
ZerOne

Reputation: 1326

Regex split at second comma

Hi I need to write a regex with following logic:

Split at every second comma except if the character '\' is before the comma.

Maybe an example to make it clear:

1,1a,2,2a,3,3a\,b,4,4a

Should get the result:

1,1a

2,2a

3,3a\,b

4,4a

This is my following code:

SELECT REGEXP_SUBSTR (text, '[^,]+,[^,]+', 1, LEVEL) TXT
FROM DUAL
CONNECT BY REGEXP_SUBSTR (text, '[^,]+,[^,]+', 1, LEVEL) IS NOT NULL;

So my regex at the moment is: '[^,]+,[^,]+' which split at every second comma.

Upvotes: 1

Views: 1931

Answers (1)

J Earls
J Earls

Reputation: 1812

Try (\\,|[^,])+ instead of plain [^,]+

Upvotes: 1

Related Questions