Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: need to parse firts part of SQL-query (regex question)

by martin (Friar)
on Jan 17, 2008 at 18:22 UTC ( #662932=note: print w/replies, xml ) Need Help??

in reply to need to parse firts part of SQL-query (regex question)

How about this: Think positive and use a regex for the fields you want rather than what might or might not separate them, like this:

my $part_sql = "f1,f2, SUM(f3),CONCAT(f4,f5, f6), f7"; my @fields = $part_sql =~ m{ (?: ^ | , ) # start of string or comma ( # begin capture (?: # either: [^,()] # non-paren non-comma | # or: \( # left paren [^()]* # any amount of non-paren \) # right paren )* # as often as possible ) # end capture }gx; # take all matches print map { "$_\n" } @fields;

Of course, this simplistic approach does not handle nested parentheses.

Replies are listed 'Best First'.
Re^2: need to parse firts part of SQL-query (regex question)
by bfdi533 (Friar) on Mar 27, 2008 at 21:32 UTC

    Quite an interesting solution. Of course, as you have stated, it does not handle nested parentheses. Which, of course, is something that I need to do.

    Any takers on how this can be adapted to handle nested parens?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://662932]
[Corion]: marto: Ow, I hope that gets better soonish! But I feel some $work-timecrunch looming at my $work as well
[Corion]: marto: Ah, so you can multiplex work and PM time ;-D
[Corion]: The upside to this is that I've reduced my $work (well, $paid) time to 80%, so I'll be at $work only four days/week, which will hopefully make the crunch less crunchy on me ;)
[marto]: yeah, so that stays as before. But before the boys were born I'd be on quite often at night (GMT) also
[marto]: I had the option during our TUPE transfer to buy 5 more days holiday. They were shocked when I did :P

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2017-06-29 08:24 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (655 votes). Check out past polls.