tags:

views:

230

answers:

2

I have a multiple line string like following:

END IF;

**EXECUTE IMMEDIATE ' CREATE INDEX #idx1
      ON somename ( row_id,
                           something)';**

   IF v_sys_error <> 0 THEN
      GOTO SQL_ERROR;

   END IF;

Edit: '**' is not in my string. I wanted to bold what i wanted to capture.

I wish to capture the part in bold (meaning everything from EXECUTE IMMEDIATE to next semicolon.

I have the following regex but how can i change it to work with multiple lines?

(EXECUTE).*;
A: 

(?m) makes the regex multiline:

/(?m)(EXECUTE).*?;/
Nosrama
A: 

The following should work in Groovy.

def s = """
END IF;

EXECUTE IMMEDIATE ' CREATE INDEX #idx1
      ON somename ( row_id,
                           something)';

   IF v_sys_error <> 0 THEN
      GOTO SQL_ERROR;

   END IF;
"""

def expect = """
EXECUTE IMMEDIATE ' CREATE INDEX #idx1
      ON somename ( row_id,
                           something)';
""".trim()

def exe = s =~ /(?ms)(EXECUTE.*?;)/

assert expect == exe[0][1]
John Wagenleitner