duanbigan7765 2012-01-11 16:01
浏览 40

在括号内匹配文本*而不是*的正则表达式

I'm looking for a regex that will match all the bold text below in a PHP (PCRE) compatible pattern, this is just an example query that it needs to match, so it can't be so specific that it won't work on other similar queries.

select a.*, (select count(*) from table1 ) as t1, (select count(*) from table2 ) as t2, (select count(*) from table3 ) as t3, col1, col2 from table4 as a LEFT JOIN ( SELECT g2.*,g1.id from table5 ) as g ON ( a.id = g.id ) );

UPDATE: My idea was to match the word FROM that is not between any brackets and everything before it. The end goal is to replace all the bold text with "COUNT()" for a database abstraction layer.

  • 写回答

2条回答 默认 最新

  • dpvv37755 2012-01-11 16:18
    关注

    If your question is "How can I use regexes to find the expressions that are selected at the top level of a SQL query," the short answer is, you can't.

    SQL is not a "regular language" (any language that allows nesting of parentheses is not), so you're blocked right there. I believe it is a context-sensitive grammar, so you would need a separate lexical analyzer and parser.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败
  • ¥15 Centos7 / PETGEM
  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题