Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: regexp_substr occurrences problem
PhilHibbs wrote:
> Why doesn't this match more than once:
>
> DECLARE
> i NUMBER := 1;
> s VARCHAR2(10);
> BEGIN
> LOOP
> s := REGEXP_SUBSTR( 'ABC|DEF|GHI|JLK', '\|[^\|]+\|', 1, i )
> EXIT WHEN s IS NULL;
> i := i + 1;
> DBMS_OUTPUT.PUT_LINE( s );
> END LOOP;
> END;
>
> All I get is |DEF| when I think I should get |GHI| as well. Where am I
> going wrong?
>
> Phil Hibbs.
No, you shouldn't. Since |DEF| matched, search continues *past* it, and next goes GHI|JLK, not |GHI|JLK - the pipe preceding G is kept with the previous match. The regexp is not a sliding window into the string.
Hth,
Vladimir M. Zakharychev
N-Networks, makers of Dynamic PSP(tm)
http://www.dynamicpsp.com
Received on Mon Sep 18 2006 - 14:42:24 CDT