RegEx help

Discussion in 'Perl Misc' started by JMosey, Jul 14, 2005.

  1. JMosey

    JMosey Guest

    I have a string of select vars from a SQL query

    i.e. Select first, second, third, fourth from table...

    I can get the part "first, second, third, fourth" just fine.

    I then turn that into a list which is used elsewhere.

    My problem is when someone does this:

    Select first, second AS NumberTwo, third, mytable.fourth from table...

    For the use I have for that srting I grab, the AS and . cause problems.

    I can say what I want the regex to do, but I have having a terrible
    time writing it.

    first, I'd like one to strip out all text backwards from "AS" until the
    previous comma (i.e. make ", second AS NumberTwo," just ", NumberTwo,"

    secondly, I'd like one that does the same thing with the period (i.e.
    make ", mytable.fourth," just ", fourth,"

    Finding the "AS" and "." are in grasp, but searching/removing backwards
    until the previous "," is a pain at this point.

    Is this even possible? Do I need to break my string into chunks at the
    comma and approach it that way?
    JMosey, Jul 14, 2005
    1. Advertisements

  2. .... you try to do Real Parsing with only regular expressions.

    They cause no problems at all for something that knows how to do
    a proper parse of an SQL statement.

    I can say that you shouldn't be using a regex for this at all. :)

    Then let someone else write the hard parts *for you*, and just re-use
    what they've developed!

    Have you searched CPAN for modules that can Parse SQL for you?

    Tad McClellan, Jul 14, 2005
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.