nmcdermaid
asked on
Parsing SQL Script with Regular Expression
Hi there,
Feel free to point me to the correct newsgroup if you can thik of a better one.
I would like to parse a SQL script using Regular Expressions
For example, I have this string in My SQL Script:
CREATE VIEW vw_Something AS
...
..
..
..
GO
I would like to grab the view name and view contents.
I've come up with this Regular expression string:
CREATE[\s]*VIEW[\s]*([\S]* )[\s]*AS
This will give me the view name in the first bracketed subselect.
Getting the view contents seems to be more difficult. I want to find all the text between these patterns:
FROM: the end of the last regular expression
TO a whitespace surround 'GO' string, so something like this:
([^[\s]GO[\s]])[\s]GO[\s]
The problem I have is a I cant 'not' match an entire string.
Can anybody help? I can reexplain if required!!!
Feel free to point me to the correct newsgroup if you can thik of a better one.
I would like to parse a SQL script using Regular Expressions
For example, I have this string in My SQL Script:
CREATE VIEW vw_Something AS
...
..
..
..
GO
I would like to grab the view name and view contents.
I've come up with this Regular expression string:
CREATE[\s]*VIEW[\s]*([\S]*
This will give me the view name in the first bracketed subselect.
Getting the view contents seems to be more difficult. I want to find all the text between these patterns:
FROM: the end of the last regular expression
TO a whitespace surround 'GO' string, so something like this:
([^[\s]GO[\s]])[\s]GO[\s]
The problem I have is a I cant 'not' match an entire string.
Can anybody help? I can reexplain if required!!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Fantastic Shiju, I had a feeling that the non greedy match was what I wanted but I couldn't work out the syntax!!
Thats great, its solved my problem.
Thats great, its solved my problem.
hi nmcdermaid
i am happy bcoz u r happy
thank u for the points
;-)
Shiju
i am happy bcoz u r happy
thank u for the points
;-)
Shiju
can u give a sample data and explain what all data u want to extract from that ?
;-)
Shiju