c# 解析提取sql中所有表名

2023-03-23  本文已影响0人  吉凶以情迁
   static List<string> GetTable(string sql)
        {

            sql = sql.Replace("'", "\"");

            List<string> tables = new List<string>();

 
            Regex regex = new Regex(@"((?![^(]*\))(?![^']*')(?i)(?:FROM|JOIN)\s+([\w\.]+))", RegexOptions.Multiline);
            MatchCollection matches = regex.Matches(sql);
            foreach (Match match in matches)
            {
                tables.Add(match.Groups[2].Value);
            }

            return tables;
        }
上一篇下一篇

猜你喜欢

热点阅读