下面的regex \(\s*select([^()]*)\)
给出了所有子查询,但忽略了子查询中包含的任何sql函数,如max()、count()等。regex的工作原理如下
SELECT student.name, teacher.name, sub.subject_name
FROM student student
JOIN teacher teacher on teacher.id=student.teacher_id
JOIN (select subject.name subject_name, subject.id id from subject) sub on sub.id=teacher.subject_id
where student.id=1
它发现子查询为select subject.name subject_name, subject.id id from subject
,而不是
SELECT student.name, teacher.name, sub.subject_name
FROM student student
JOIN teacher teacher on teacher.id=student.teacher_id
JOIN (select group_concat(subject.name) subject_names from subject)
where student.id=1
找不到select group_concat(subject.name) subject_names from subject
这样的匹配项,如何才能获得匹配项...?
2条答案
按热度按时间vs91vp4v1#
您可以尝试使用regex
/\((?:[^()]|\((?:[^()]|\([^()]*\))*\))*\)/mg;
yhived7q2#
接受挑战。看看这是否会导致可行的解决方案:
然后使用/*.. */注解和平衡括号解析EXPLAIN。
(我编辑了空格以达到效果。)