Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: regexp_substr occurrences problem

Re: regexp_substr occurrences problem

From: Vladimir M. Zakharychev <vladimir.zakharychev_at_gmail.com>
Date: 18 Sep 2006 12:42:24 -0700
Message-ID: <1158608544.615112.148490@m73g2000cwd.googlegroups.com>

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

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US