譬如select * from table as a
我要找出
from table
table as
as a
所有连续的两个词
这个正则表达式怎么搞呢?

解决方案 »

  1.   

    匹配空格或者TAB等前后均有单词的,这样不就是相邻的两个单词了?
      

  2.   

    String pattern = @"(\w+) (\w+)";
    Regex regex = new Regex(pattern, RegexOptions.Singleline );
    Match match = regex.Match("select * from table as a");
    while (match.Success) 
    {
    MessageBox.Show(match.Value);
    match = regex.Match("select * from table as a", match.Groups[2].Index);
    }
      

  3.   

    [\w]*\s[\w]*\s
    不能匹配select * from table as a,但是把*改成字符就可以.
    测试通过..