Just to update you all on this:

I have come up with a regex in Python that does what I want but I
still can't get the same regex patten to work in Oracle.

Python:
import re
source = """BEGIN
   -- DEVELOPMENT HISTORY
       -- Original author: x
    -- Creation date: y
-- CR z
   v_user varchar2(30) := USER;
"""
p = re.compile('^[\t\x20]*[^- ]{2}.*?$', re.MULTILINE)
print(source)
match = re.finditer(p, source)
for m in match:
    print(m.start(), m.end(), m.group())
## Correctly produces:
##    0 5 BEGIN
##    93 124    v_user varchar2(30) := USER;

Oracle:
select regexp_instr( 'BEGIN
   -- DEVELOPMENT HISTORY
       -- Original author: x
    -- Creation date: y
-- CR z
   v_user varchar2(30) := USER;
', '^[\t\x20]*[^- ]{2}.*?$', 13, 1, 0, 'm' )
from dual;

Unexpectedly returns 0.  The reason I start searching from character
13 is because I want to get past the 'BEGIN'.

Can anybody help me with this?

On Jul 22, 12:05 pm, VTR250 <goo...@m-streeter.demon.co.uk> wrote:
> Hi,
>
> I am using REGEXP to search through an Oracle listing.  At some point
> in the listing I have some several lines of in-line comments.  The
> comments might not be had up against the left margin, so there may be
> some leading spaces (this is what is tripping me up).
>
> This regexp_instr gives me 83 (correct):
> -- I want to find the next newline that is NOT followed by '--' (may
> have some whitespace too).
> select regexp_instr( 'BEGIN
>    -- DEVELOPMENT HISTORY
> -- Original author: x
> -- Creation date: y
> -- CR z
>    v_user varchar2(30) := USER;
> ', '^[\t\x20]*?[^-{2}]', 13, 1, 0, 'm' )
> from dual;
>
> ...but this one gives me 33 (i have added 9 spaces, so I want 93):
> -- I want to find the next newline that is NOT followed by '--' (may
> have some whitespace too).
> select regexp_instr( 'BEGIN
>    -- DEVELOPMENT HISTORY
>    -- Original author: x
>    -- Creation date: y
>    -- CR z
>    v_user varchar2(30) := USER;
> ', '^[\t\x20]*?[^-{2}]', 13, 1, 0, 'm' )
> from dual;
>
> The regexp I have at the moment is:
>    ^ - start of line
>    [\t\x20]*? - tab or space, zero or more, non-greedy
>    [^--[2]] - anything except '--'
>
> The difference is the space at the start line '-- Original author...';
> if I take all the leading spaces away from the comments, it correctly
> matches the line starting 'v_user'.
> I've tried [ ]*?, [\x20]*?, [\s]*?, omitting the '?' etc. nothing
> makes any difference.
> I'm about to try this in Perl. I can't report it as a bug in Oracle
> until I observe a regexp actually working. I have tried for a long
> time with this, but cannot get I even think there may be a bug in the
> Oracle implementation of regexp!
> Can anybody here see something that I'm obviously doing wrong?
>
> Thanks for your help!

-- 
You received this message because you are subscribed to the Google
Groups "Oracle PL/SQL" group.
To post to this group, send email to Oracle-PLSQL@googlegroups.com
To unsubscribe from this group, send email to
oracle-plsql-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/Oracle-PLSQL?hl=en

Reply via email to