美文网首页
c# 解析提取sql中所有表名

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

作者: 吉凶以情迁 | 来源:发表于2023-03-23 09:08 被阅读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;
            }
    

    相关文章

      网友评论

          本文标题:c# 解析提取sql中所有表名

          本文链接:https://www.haomeiwen.com/subject/hwbvrdtx.html