[問題] 類似SQL的Parser
看板RegExp (正規表示式 Regular Expression)作者Geniusking (真理斯金)時間15年前 (2010/05/20 21:10)推噓0(0推 0噓 2→)留言2則, 2人參與討論串1/2 (看更多)
我的String是一個像SQL的Query,有sub select:
select A, B from Table where city in
( select id from Table where name in
( select name from Table where id=J ))
現在用
preg_match("/SELECT (.+) FROM (.+) WHERE (.+) IN \([\s]*(.+)\)$/i", $q, $m)
Match的結果是(找到第二個from了):
Array (
[0] => select A, B from Table where city in ( select id from Table where name in ( select name from Table where id=J ))
[1] => A, B from Table where city in ( select id
[2] => Table
[3] => name
[4] => select name from Table where id=J )
)
我想要的結果是
Array (
[0] => select A, B from Table where city in ( select id from Table where name i
[1] => A, B
[2] => Table
[3] => name
[4] => select id from Table where name in ( select name from Table where id=J )
)
請問要怎麼做才好?謝謝
--
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.113.198.98
→
05/20 22:44, , 1F
05/20 22:44, 1F
→
05/28 16:52, , 2F
05/28 16:52, 2F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):
RegExp 近期熱門文章
PTT數位生活區 即時熱門文章