正則表達式提取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

相關文章
相關標籤/搜索