Match CASE/END SQL Construct

I am working on a SQL parser. I have a routine that recursively removes
enclosing parentheses and it works fine. Below is the regex that I use.

However, I want to use the same routine, but instead of looking for
enclosing parens, I want to look for a string enclosed by CASE and END. Can
someone help me translate the regex below so that it will match a CASE/END
construct?

Advertisements

Guest

On Thu, 15 Jan 2009 15:05:29 -0500, "Perry Aynum" <> wrote:
>I am working on a SQL parser. I have a routine that recursively removes
>enclosing parentheses and it works fine. Below is the regex that I use.
>
>However, I want to use the same routine, but instead of looking for
>enclosing parens, I want to look for a string enclosed by CASE and END. Can
>someone help me translate the regex below so that it will match a CASE/END
>construct?
>
>Thanks very much.
>
>Parens
>----------
>(?:\s+)?\([^\(\)]*\)
>
>
>
>This is what I've managed so far with the CASE/END
>
>(?:\s+)?case(?!case|end)\s+end
>
Its probably not this simple.

Advertisements

In article <9GMbl.19524$>, Perry Aynum
<> wrote:
> I am working on a SQL parser. I have a routine that recursively removes
> enclosing parentheses and it works fine. Below is the regex that I use.
>
> However, I want to use the same routine, but instead of looking for
> enclosing parens, I want to look for a string enclosed by CASE and END. Can
> someone help me translate the regex below so that it will match a CASE/END
> construct?
>
> Thanks very much.
>
> Parens
> ----------
> (?:\s+)?\([^\(\)]*\)
>
>
>
> This is what I've managed so far with the CASE/END
>
> (?:\s+)?case(?!case|end)\s+end

Jim Gibson <> wrote:
> In article <9GMbl.19524$>, Perry Aynum
><> wrote:
>> recursively removes
>> enclosing parentheses
>> However, I want to use the same routine, but instead of looking for
>> enclosing parens, I want to look for a string enclosed by CASE and END.

Guest

On Thu, 15 Jan 2009 15:05:29 -0500, "Perry Aynum" <> wrote:
>I am working on a SQL parser. I have a routine that recursively removes
>enclosing parentheses and it works fine. Below is the regex that I use.
>
>However, I want to use the same routine, but instead of looking for
>enclosing parens, I want to look for a string enclosed by CASE and END. Can
>someone help me translate the regex below so that it will match a CASE/END
>construct?
>
>Thanks very much.
>
>Parens
>----------
>(?:\s+)?\([^\(\)]*\)
>
>
>
>This is what I've managed so far with the CASE/END
>
>(?:\s+)?case(?!case|end)\s+end
>

I've revisited this, became intrigued with zero-assertion width
extented regexp constructs. These constructs don't get enough air-time
here. Since you appear to be leaning in that direction, I thought I would
flesh out a look ahead regexp for your example, perhaps to try to glean insight on
the regexp engine, not really sure. Its very facinating for me. I'm not a big book
reader since I am dislexic, so I try to discover things on my own.

The below would seem to tackle your problem from the perspective of a file slurped
into a variable which is processed. All relavent delimeters are taken into acccount,
my other penchant is for parsing. It is possible to buffer line by line file info
until we just have enough to parse. I didn't do it of course but it is fairly easy.
This would aviod sucking up huge amounts of memory, and is fairly trivial once the
master regexp is known.

I've learned some stuff about the regexp engine's extended operations. I won't go into it.
I decided to include the progression of guesses that went into settling on its final form.
Obviously this form does take into account several delimiting factors as well as look-ahead.
Its not fully tested of course, but it passes my initial alpha form that could be
presented to testers.

As it is now, CASE/END are the targets, however, any can be substituted.
Should you like to employ me for extended projects, set up a contact arangement.

Note the code is at the bottom, the output is at the top, in true dyslexic fashion.
Particularly note in the output, how inner to outter matching goes. This is key.

Guest

On Tue, 20 Jan 2009 20:08:02 GMT, wrote:
>On Thu, 15 Jan 2009 15:05:29 -0500, "Perry Aynum" <> wrote:
>
>>I am working on a SQL parser. I have a routine that recursively removes
>>enclosing parentheses and it works fine. Below is the regex that I use.
>>
>>However, I want to use the same routine, but instead of looking for
>>enclosing parens, I want to look for a string enclosed by CASE and END. Can
>>someone help me translate the regex below so that it will match a CASE/END
>>construct?
>>
>>Thanks very much.
>>
>>Parens
>>----------
>>(?:\s+)?\([^\(\)]*\)
>>
>>
>>
>>This is what I've managed so far with the CASE/END
>>
>>(?:\s+)?case(?!case|end)\s+end
>>
>

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!