Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: regexp_substr occurrences problem
Maxim Demenko wrote:
> PhilHibbs schrieb:
> > So what should I write to get DEF and GHI out of 'ABC|DEF|GHI|JKL',
> > assuming variable length and number of segments, e.g.
> > 'A|BC|DEF|GHIJ|KLMNO' should match 'BC', 'DEF', and 'GHIJ'?
> >
> > Phil Hibbs.
> >
>
> Not knowing much about your restrictions, for the case you requested
> simple '\|.+\|' will suffice.
>
> Best regards
>
> Maxim
Nope, it won't. Since + is greedy, this RE will match |BC|DEF|GHIJ|, which is not what the OP wants. If I got him correctly, he wants to tokenize a string that uses pipe characters as separators, but he doesn't need the leading and the trailing token. So I think the right expression would be simply '[^\|]+' and regexp_substr should be called with occurence starting at 2 and ending at n-1, where n is the number of tokens in the string (n can't be told apriori, but the last token can be easily detected as n+1'th occurence will return NULL.)
Regards,
Vladimir M. Zakharychev
N-Networks, makers of Dynamic PSP(tm)
http://www.dynamicpsp.com
Received on Tue Sep 19 2006 - 12:52:06 CDT
![]() |
![]() |