正则表达式提取string 中的表名

 

  简单版本:web

 
Regex reg = new Regex(@"(?i)\bfrom\b(?![^\[\]]*\])\s+(\[[^\[\]]+\]|\S+)");
MatchCollection mc = reg.Matches(yourStr);
foreach (Match m in mc)
{
    richTextBox2.Text += m.Groups[1].Value + "\n"; 
}

 

 
支持过滤join,left join等复杂联表过滤表名
 
Regex reg = new Regex(@"(?in)\b(from|(left|right|INNER)\s+join)\b(?![^\[\]]*\])\s+(?<table>\[[^\[\]]+\]|\S+)");
MatchCollection mc = reg.Matches(yourStr);
foreach (Match m in mc)
{
    richTextBox2.Text += m.Groups["table"].Value + "\n";
}

 

原帖: http://bbs.csdn.net/topics/330116986spa

相关文章
相关标签/搜索