So4ne
So4ne

Reputation: 1182

Get second occurrence with regexp_substr

I can't achieve to make sqlfiddle work so here is my simple code :

select REGEXP_SUBSTR(' EG SUZ SG SIN blabla ', '^(\s?[A-Z]{2} [A-Z]{3}\s?){2}') from dual;

I want to get SG SIN. I know REGEXP_SUBSTR got a parameter used to get the nth occurrence but when I write

select REGEXP_SUBSTR(' EG SUZ SG SIN blabla ', '^(\s?[A-Z]{2} [A-Z]{3}\s?){2}'),1,2) from dual;

it returns nothing and 1,1 returns EG SUZ SG SIN so my guess is that the occurrence is not rightly splitted,but I don't know why, can you explain me?

Upvotes: 2

Views: 9675

Answers (1)

rock321987
rock321987

Reputation: 11032

This will work

select REGEXP_SUBSTR(' EG SUZ SG SIN blabla ', '([A-Z]{2} [A-Z]{3}(\s|$))', 1, 2) from dual;

Upvotes: 1

Related Questions