开发者

split: regex to ignore delimiters inside balanced parenthesis

I've got ORDER BY part of the statement and I have to split it at logical parts

my $sql_part = <<EOH
    IF(some_table.some_field <> 3, 1, 0), 
    some_table.other_field, 
    CASE other_table.third_field WHEN IS NULL THEN 2 ELSE 1 END,
    other_table.third_field
EOH

and, you know, original string doesn't contain newlines and IF's can be nested.

The problem is I don't want to split the stuff inside the nested IF's, function calls.

So simple split /\s*,\s*/, $sql_part won't work.

Is there a regex that can do this, or should I do it just differentl开发者_JS百科y?


There is a regex, but you probably want to just use an SQL Parser: SQL::Statement

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜