我有一个查询,想要获取 from & where
之间的表名。如果是单行且没有别名的单个表,我可以这样做:
(?<=from )([^#]\w*)(?=.*where)
我需要获取除有前缀表格之外的每个表格,例如
course c
marks s
。但我无法找出以下查询的正则表达式。 (
where
子句可能在同一行或新行中,位于行的开头或带有空格或制表符)
from #prefix#student, course c, marks m
where ....
有些地方还涉及到子查询,如果能处理这种情况会很有帮助。
select ... from course c
where id = (select ... from student where ...)
我正在尝试在sublime text 3
编辑器中查找和替换
测试案例查询:
//output [course]
select ... from course
where ...
//output [course c] [marks s]
select ... from course c, marks s
where ....
//output [marks m]
select ... from #prefix#course c, marks m
where ...
//output [student s]
select ... from #prefix#course c
where id = (select ... from student s where ...)
\bfrom([^w]*(?:\bw(?!here\b)[^w]*)*)where
。 - Wiktor Stribiżewfrom
开头的任何子字符串后跟#
,我宁愿使用\bfrom(?!\s*#)([^w]*(?:\bw(?!here\b)[^w]*)*)where
。 - Wiktor Stribiżew