简体   繁体   English

split:正则表达式忽略平衡括号内的定界符

[英]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 我已经将该语句的一部分作为ORDER BY,并且必须在逻辑部分进行拆分

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. 而且,您知道原始字符串不包含换行符,并且IF可以嵌套。

The problem is I don't want to split the stuff inside the nested IF's, function calls. 问题是我不想在嵌套的IF函数调用中拆分内容。

So simple split /\\s*,\\s*/, $sql_part won't work. 因此,简单的split /\\s*,\\s*/, $sql_part将不起作用。

Is there a regex that can do this, or should I do it just differently? 有没有可以做到这一点的正则表达式,或者我应该做些不同的事情吗?

有一个正则表达式,但是您可能只想使用一个SQL解析器: SQL :: Statement

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM